Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'Ctrl' key pressed while clicking a button?

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.

like image 927
codekitty Avatar asked Apr 11 '12 17:04

codekitty


People also ask

What happens when you press Ctrl key?

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.

What is Ctrl click button?

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.

Why does my keyboard keep pressing Ctrl?

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.

How can I tell if a key is pressed on my keyboard?

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.


2 Answers

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.

like image 77
Pursuit Avatar answered Oct 07 '22 20:10

Pursuit


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.

like image 21
dfergenson Avatar answered Oct 07 '22 21:10

dfergenson