I need to know whether the user is holding down the ctrl key while clicking a button. Since it's a button and not a figure I cannot use 'selectionType' on the figure etc.
Pressing the Ctrl key by itself does nothing in most programs. In computer games, Ctrl is often used to crouch or go into a prone position. Pressing Ctrl and 0 (zero) at the same time restores the default zoom level. Switches to the first tab in a browser or another program with tab support.
While in a browser, pressing and holding Ctrl and then clicking any hyperlink opens that link in a new tab. This shortcut is helpful for when you're reading a web page and are interested in a link, but want to continue reading the current page.
This could be caused by the 'Sticky Keys' function (an accessibility option). If you are on Windows 7, click on the start button go to Control Panel, ease of access, change how your keyboard works. Under the option 'Make it easier to type', uncheck 'Turn on Sticky keys' and see if this solves your problem.
The Windows on-screen keyboard is a program included in Windows that shows an on-screen keyboard to test modifier keys and other special keys. For example, when pressing the Alt , Ctrl , or Shift key, the On-Screen Keyboard highlights the keys as pressed.
How about this:
modifiers = get(gcf,'currentModifier'); %(Use an actual figure number if known)
ctrlIsPressed = ismember('control',modifiers);
The figure class has a number of useful Current*
properties which are useful when handling callbacks. This is how to retrieve current mouse position, selected graphics object, and (as here) pressed keys. These include: CurrentAxes, CurrentCharacter, CurrentKey, CurrentModifier, CurrentObject, and CurrentPosition.
Pressing the escape key reinitializes CurrentModifier. My solution so far has been to instruct my users (right in the GUI) to press the escape key to revert to default behavior.
Overall, Matlab's CurrentModifier behavior seems to be that the modifier key "sticks" until one of the following occurs: a different modifier is pressed, a different window is selected, or the escape key is pressed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With