2014-01-26 55 views
0

从Linux我想为Windows 7/8和Mac做一个小的可执行文件。 与PureBasic language。 如何使用PureBasic按F1或F2键盘按钮? 我试过,但得到一个链接错误。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

在Windows下你可以发布如下消息:

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

所以,你应该找到你的语言,一种方式PostMessage的到你的窗口。还有其他的赢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