Page 1 of 1
How to catch system keys
Posted: Mon Aug 13, 2007 12:12 pm
by PBasic
I saw KeyboardInkey() returns the last typed character, but I want my program to react when I press Alt, Shift, F1->F12, Ctrl etc...
How do I do that?
Thanks.
Posted: Mon Aug 13, 2007 12:18 pm
by Fluid Byte
Have a look under "Keyboard" in the docs.
Posted: Mon Aug 13, 2007 12:45 pm
by Kaeru Gaman
mind that the keyboard-lib is for screen-apps only.
Posted: Mon Aug 13, 2007 12:48 pm
by gnozal
The keyboard library uses Direct-X iirc.
If you don't need / want it, you may have a look at GetAsyncKeyState_() (Windows API).
Posted: Mon Aug 13, 2007 1:10 pm
by Kaeru Gaman
if you want only a few single keys for use in a win-app, you can also go via HotKeys...
so you see, it would be good to have hints what your aim is...
Posted: Tue Aug 14, 2007 5:12 am
by netmaestro
If you're making a gui (window with gadgets) and you're processing the keypresses while your program is focused, probably the best way is to use AddKeyboardShortCut():
Code: Select all
#ControlF5 = 1
OpenWindow(0,0,0,320,240,"Keyboard Shortcut Demo",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
; add gadgets here
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_F5, #ControlF5)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case #ControlF5
Debug "You pressed Control-F5!"
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow