2

How can I detect that two or three combination keys are pressed?

For example when i press 'Shift + Ctrl + F1' how can i detect it in 'onKeyDown' event of a textbox?

2
  • 2
    if (Shift = [ssCtrl]) and (Key = VK_F1) then DoSomething;
    – TLama
    Apr 13, 2014 at 5:00
  • tnx alot, but for pressing 'Shift+Alt+F1' what can i do? i mean how my app could understand that shift and alt are pressed in onKeyDown or onKeyUp?
    – Rojin
    Apr 13, 2014 at 5:59

1 Answer 1

5

The Shift parameter to OnKeyDown is a set. It describes the state of all the modifier keys. Test for multiple modifier keys like this:

if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssShift,ssCtrl] then
  ....

The * picks out the state of the three modifier keys from Shift. The test then checks for shift and ctrl being down, but alt not being down.

Such key presses are usually best handled by actions using the ShortCut property of an action.

3
  • tnx alot, best regards.
    – Rojin
    Apr 13, 2014 at 6:30
  • 1
    .. or Shift = [ssShift, ssCtrl], depending on requirement. Apr 13, 2014 at 16:39
  • @sertac I think you have to mask out the non modifiers Apr 13, 2014 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.