From Linux i am trying to make a small executable file for Windows 7/8 and Mac. with PureBasic language. How can i press F1 or F2 keyboard button using PureBasic? I tried following but getting a linker error.
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 200, 200, "Shortcut test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Apps,101); (=) - somewhere near the Space key
AddKeyboardShortcut(0, #PB_Shortcut_Clear,102)
AddKeyboardShortcut(0, #PB_Shortcut_Command,103)
AddKeyboardShortcut(0, #PB_Shortcut_Execute,104)
AddKeyboardShortcut(0, #PB_Shortcut_Help,105)
AddKeyboardShortcut(0, #PB_Shortcut_Menu,106)
;AddKeyboardShortcut(0, #PB_Shortcut_Next,107)
AddKeyboardShortcut(0, #PB_Shortcut_Pause,108); Pause - should be beside F12 or so
AddKeyboardShortcut(0, #PB_Shortcut_Print,109)
;AddKeyboardShortcut(0, #PB_Shortcut_Prior,110)
AddKeyboardShortcut(0, #PB_Shortcut_Scroll,111); ScrollLock
AddKeyboardShortcut(0, #PB_Shortcut_Select,112)
AddKeyboardShortcut(0, #PB_Shortcut_Separator,113)
AddKeyboardShortcut(0, #PB_Shortcut_Snapshot,114)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
z=EventMenu()
If z>99 And z<115
Debug "Found key for the event #"+Str(z)
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
Under Windows you can post following messages:
PostMessage(hWnd, WM_KEYDOWN, VK_F1, 0);
PostMessage(hWnd, WM_KEYUP, VK_F1, 0);
So you should find in your language, a way to PostMessage to your window. There are other Win API functions like: keybd_event, SendInput look here for more info:
http://www.codeproject.com/Articles/2334/Toggling-the-Num-Lock-Caps-Lock-an-Scroll-Lock-ke
I know nothing about PureBasic but after quick googling I was able to find forum where something similar is being done: