Page 1 of 1

check pressed key/combination

Posted: Fri Jul 29, 2016 5:07 pm
by Yuri_D
Hi!

I'd like to add additional hidden options to button gadgets and made them available only when a specific key combination is pressed.
Could you please advise an easiest way to read pressed key/s when the button gadget is kicked?

Thank you in advance!

Re: check pressed key/combination

Posted: Fri Jul 29, 2016 5:55 pm
by TI-994A
Yuri_D wrote:...an easiest way to read pressed key/s when the button gadget is kicked?
A Windows-only solution:

Code: Select all

Enumeration
  #MainWindow
  #Button
EndEnumeration

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 200, "Masked-Click (Windows Only)", wFlags)
ButtonGadget(#Button, 100, 80, 100, 30, "Button")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button
          If GetAsyncKeyState_(#VK_SHIFT)
            Debug "Button clicked with shift"
          ElseIf GetAsyncKeyState_(#VK_CONTROL)
            Debug "Button clicked with control"
          Else
            Debug "Button clicked"
          EndIf
      EndSelect
  EndSelect
Until appQuit
Hope it helps. :wink:

Re: check pressed key/combination

Posted: Fri Jul 29, 2016 7:32 pm
by Yuri_D
Thank you, GetAsyncKeyState_ command is what I was looking for!

Re: check pressed key/combination

Posted: Sat Jul 30, 2016 12:01 pm
by doctorized
Yuri_D wrote:Thank you, GetAsyncKeyState_ command is what I was looking for!
Once upon a time, I used GetAsyncKeyState in an app of mine and some antivirus solutions reported that my app is a variant of a keylogger because of the use of this API. So, I replaced it with a hotkey and since then I have no problem. Tell me if you want the code.