简体   繁体   中英

Simulating UP arrow keybd_event (not working?)

keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0); //pressed
Sleep(100);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0); //released
Sleep(300);

The following is not automatically pressing the UP arrow and releasing it like it should. Am I doing something wrong?

The keybd_event function is obsolete. It has been superseded by the SendInput function .

The following code might do what you want.

UINT SendUpArrow()
{
    INPUT input[2] = {0};
    input[0].type = INPUT_KEYBOARD;
    input[0].ki.wVk = VK_UP;
    input[0].ki.dwFlags = 0;
    input[1].type = INPUT_KEYBOARD;
    input[1].ki.wVk = VK_UP;
    input[1].ki.dwFlags = KEYEVENTF_KEYUP;
    UINT ret = ::SendInput(_countof(input), input, sizeof(INPUT));
    return ret;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM