Ask Your Question
0

Button Macro plus Shift or Ctrl Key

asked 2018-04-13 15:52:03 +0200

kaduleite gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-04-13 17:23:25 +0200

Ratslinger gravatar image

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 ✔ (upper left area of answer). It helps others to know there was an accepted answer.

edit flag offensive delete link more

Comments

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.

kaduleite gravatar imagekaduleite ( 2018-04-14 16:21:00 +0200 )edit
1

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.

Ratslinger gravatar imageRatslinger ( 2018-04-14 16:40:23 +0200 )edit

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.

João Luís gravatar imageJoão Luís ( 2018-12-16 19:15:30 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-04-13 15:52:03 +0200

Seen: 138 times

Last updated: Apr 13 '18