1 /*
2  * PROJECT:     ReactOS api tests
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Test for keyboard inputs with flags KEYEVENTF_EXTENDEDKEY and KEYEVENTF_SCANCODE
5  * COPYRIGHT:   Copyright 2021 Arjav Garg <arjavgarg@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
10 static void testScancodeExtendedKey(BYTE wVk, BYTE scanCode)
11 {
12     trace("wVK: %x\tScancode: %x\n", wVk, scanCode);
13 
14     keybd_event(0, scanCode, KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY, 0);
15     SHORT winKeyState = GetAsyncKeyState(wVk);
16     ok(winKeyState & 0x8000, "VK=%x should be detected as key down.\n", wVk);
17 
18     keybd_event(0, scanCode, KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
19     winKeyState = GetAsyncKeyState(wVk);
20     ok(!(winKeyState & 0x8000), "VK=%x should be detected as key up.\n", wVk);
21 }
22 
23 /* https://docs.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#extended-key-flag */
24 START_TEST(keybd_event)
25 {
26     testScancodeExtendedKey(VK_RWIN, 0x5C);
27     testScancodeExtendedKey(VK_LWIN, 0x5B);
28     testScancodeExtendedKey(VK_RMENU, 0x38);
29     testScancodeExtendedKey(VK_RCONTROL, 0x1D);
30     testScancodeExtendedKey(VK_INSERT, 0x52);
31     testScancodeExtendedKey(VK_DELETE, 0x53);
32     testScancodeExtendedKey(VK_HOME, 0x47);
33     testScancodeExtendedKey(VK_END, 0x4f);
34     testScancodeExtendedKey(VK_PRIOR, 0x49);
35     testScancodeExtendedKey(VK_NEXT, 0x51);
36     testScancodeExtendedKey(VK_UP, 0x48);
37     testScancodeExtendedKey(VK_RIGHT, 0x4d);
38     testScancodeExtendedKey(VK_LEFT, 0x4b);
39     testScancodeExtendedKey(VK_DOWN, 0x50);
40     testScancodeExtendedKey(VK_DIVIDE, 0x35);
41     testScancodeExtendedKey(VK_RETURN, 0x1C);
42 }
43