PureBasic - 我如何模拟按F1或F2键盘按钮?

时间:2014-01-26 10:31:15

标签: linux windows macos keyboard-shortcuts basic

从Linux我试图为Windows 7/8和Mac制作一个小的可执行文件。 与PureBasic language。 如何使用PureBasic按F1或F2键盘按钮? 我试过跟踪但是收到链接器错误。

enter image description here

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

1 个答案:

答案 0 :(得分:1)

在Windows下,您可以发布以下消息:

    PostMessage(hWnd, WM_KEYDOWN, VK_F1, 0);
    PostMessage(hWnd, WM_KEYUP, VK_F1, 0);

所以你应该用你的语言找到PostMessage到窗口的方法。还有其他Win API函数,如:keybd_event,SendInput在这里查看更多信息:

http://www.codeproject.com/Articles/2334/Toggling-the-Num-Lock-Caps-Lock-an-Scroll-Lock-ke

我对PureBasic一无所知,但经过快速谷歌搜索,我找到了类似的东西的论坛:

http://www.purebasic.fr/english/viewtopic.php?f=13&t=47321