开发者

How to press the keys on keyboard without using keyboard?

开发者 https://www.devze.com 2022-12-27 01:11 出处:网络
I want my program to press certain keys on my keyboard without me doing it physically. How i do this? Edit: found this keybd_event() function. seem to be wor开发者_如何学Pythonking

I want my program to press certain keys on my keyboard without me doing it physically.

How i do this?

Edit: found this keybd_event() function. seem to be wor开发者_如何学Pythonking http://www.codeproject.com/KB/cpp/sendkeys_cpp_Article.aspx


There is SendInput function that can generate keystrokes and other kinds of input. I have used to create application similar to virtual keyboards.

Example using Unicode:

// This may be needed
// #define _WIN32_WINNT 0x0501 

#include <windows.h>
#include <winuser.h>

void    pressKey(WORD a_unicode)    
{       
        KEYBDINPUT kbinput;
        ZeroMemory(&kbinput, sizeof(kbinput));
        kbinput.wScan = a_unicode;
        kbinput.dwFlags = KEYEVENTF_UNICODE; 
        kbinput.time = 0;

        INPUT input;
        ZeroMemory(&input, sizeof(input));
        input.type = INPUT_KEYBOARD;
        input.ki = kbinput;

        SendInput(1, &input, sizeof(input));
}   


Send Key Events


Use SendMessage with WM_KEYDOWN

Example:

SendMessage(hwnd, WM_KEYDOWN, VK_T, NULL);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号