How to catch system keys

Just starting out? Need help? Post your questions and find answers here.
PBasic
New User
New User
Posts: 6
Joined: Tue May 22, 2007 2:47 pm

How to catch system keys

Post 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.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Have a look under "Keyboard" in the docs.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

mind that the keyboard-lib is for screen-apps only.
oh... and have a nice day.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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