check pressed key/combination

Just starting out? Need help? Post your questions and find answers here.
Yuri_D
User
User
Posts: 68
Joined: Wed Apr 13, 2016 7:39 am

check pressed key/combination

Post 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!
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: check pressed key/combination

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Yuri_D
User
User
Posts: 68
Joined: Wed Apr 13, 2016 7:39 am

Re: check pressed key/combination

Post by Yuri_D »

Thank you, GetAsyncKeyState_ command is what I was looking for!
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: check pressed key/combination

Post 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.
Post Reply