开发者

How would I use Keybd_event to send "A" for example?

I am trying to write a program to be able to control the keyboard. I have tried SendInput() & keybd_event already and have a block that doesnt seem to work.

I need it to be able to use keybd_event() to hold shift and press the get at the front of a queue. the VKey is retrieved with:

Vkeys.GetKey(KeyQueue.front());

The scan code is retrieved by:

MapVirtualKey(Vkeys.GetKey(KeyQueue.front()), MAPVK_VK_TO_VSC)

I need it to use th开发者_开发知识库is and press this key defined here.

Can anyone help?


Moderately messy to do: try something that looks like this. The code below queues up the shift/alt/ctrl keys, then uses the keycode (you could set the scancode if you have to, but I've not tried it before; I only had to send ASCII) and then sends keyup events to release the shift/alt/ctrl buttons.

void SendSingleKey(int keycode, bool shift, bool ctrl, bool alt)
{
    INPUT * key, keys[8];
    UINT ret = 0;

    if(shift){
        key = &(keys[ret++]);
        key->ki.wVk = VK_SHIFT;
        key->type = INPUT_KEYBOARD;
        key->ki.dwFlags = 0;
        key->ki.time = 0;
        key->ki.wScan = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    if(ctrl){
        key = &(keys[ret++]);
        key->ki.wVk = VK_CONTROL;
        key->type = INPUT_KEYBOARD;
        key->ki.dwFlags = 0;
        key->ki.time = 0;
        key->ki.wScan = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    if(alt){
        key = &(keys[ret++]);
        key->ki.wVk = VK_MENU;
        key->type = INPUT_KEYBOARD;
        key->ki.dwFlags = 0;
        key->ki.time = 0;
        key->ki.wScan = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    key = &(keys[ret++]);
    key->type = INPUT_KEYBOARD;
    key->ki.wVk = keycode;
    key->ki.dwFlags = 0;
    key->ki.time = 0;
    key->ki.wScan = 0;
    key->ki.dwExtraInfo = GetMessageExtraInfo();

    key = &(keys[ret++]);
    key->type = INPUT_KEYBOARD;
    key->ki.wVk = keycode;
    key->ki.dwFlags = KEYEVENTF_KEYUP;
    key->ki.time = 0;
    key->ki.wScan = 0;
    key->ki.dwExtraInfo = GetMessageExtraInfo();

    if(alt){
        key = &(keys[ret++]);
        key->type = INPUT_KEYBOARD;
        key->ki.wVk = VK_MENU;
        key->ki.wScan = 0;
        key->ki.dwFlags = KEYEVENTF_KEYUP;
        key->ki.time = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    if(ctrl){
        key = &(keys[ret++]);
        key->type = INPUT_KEYBOARD;
        key->ki.wVk = VK_CONTROL;
        key->ki.wScan = 0;
        key->ki.dwFlags = KEYEVENTF_KEYUP;
        key->ki.time = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    if(shift){
        key = &(keys[ret++]);
        key->ki.wVk = VK_SHIFT;
        key->type = INPUT_KEYBOARD;
        key->ki.wScan = 0;
        key->ki.dwFlags = KEYEVENTF_KEYUP;
        key->ki.time = 0;
        key->ki.dwExtraInfo = GetMessageExtraInfo();
    }
    SendInput(ret,keys,sizeof(INPUT));
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜