Button Macro plus Shift or Ctrl Key

Is there a way to detect when a button is pressed while the shift or control key is simultaneously pressed?

I used XRay to inspect the Event, but there’s no clue there.

Thanks.

Kadu Leite

Hello,

The answer presents multiple problems. Pressing keys such as Shift, Ctrl or Alt by themselves are not captured as a keystroke but can be detected when used in combination with other keys ( a, b, c etc.). When this occurs, the keycode is available and also a ‘modifier’. This modifier specifies the extra key (if present) that was used: constants group KeyModifier.

Now the closest method seen for your request would be the Key Pressed event of the button. If the button is the current control and Shift + something OR Ctrl + something is pressed, the event is triggered but not if the button is clicked or spacebar is used. You can then determine from the event that it came while the button was the current control & whether the Shift or Ctrl key was pressed. Now this is a real kludge and somewhat confusing to the user!

It may just be entirely better to implement a key handler to look for a specific key combination instead of modifier + button to determine your event. You can find more info on key handling in Andrew Pintonyak’s document AndrewMacro in section 14 found here → Andrew Pitonyak’s OpenOffice Macro Information. It is on the first line of first paragraph as OpenOffice.org Macro document.

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

Thank you very much.
I had tried the “Listing 14.14: Complete mouse click handler” in the Andrew Pintonyak’s document AndrewMacro and I think it will solve my question.

I am glad you found it useful. Keep in mind, a button can be activated in other ways that a mouse click. If tabbed to the spacebar will execute it or if a default button the Enter key does it. Just be aware of other possibilities.

I tried aKeyEvent.Modifiers = 3 and the result was a Ctrl+Shift combination. For numbers, 5, 6 and 7, we have Alt+Shift, Ctrl+Alt and Ctrl+Alt+Shift respectively.