comctl32/tests: Add hold_key and release_key functions.

Add functions to simulate the holding of keys like SHIFT, CTRL,...

Move existing SHIFT key press emulation to these functions.

Signed-off-by: Angelo Haller <angelo@szanni.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Angelo Haller 2022-04-28 08:20:09 -05:00 committed by Alexandre Julliard
parent 753fbb28d5
commit 2d78448464
1 changed files with 26 additions and 9 deletions

View File

@ -462,6 +462,30 @@ static const struct message listview_end_label_edit_kill_focus[] = {
{ 0 }
};
static void hold_key(int vk)
{
BYTE kstate[256];
BOOL res;
res = GetKeyboardState(kstate);
ok(res, "GetKeyboardState failed.\n");
kstate[vk] |= 0x80;
res = SetKeyboardState(kstate);
ok(res, "SetKeyboardState failed.\n");
}
static void release_key(int vk)
{
BYTE kstate[256];
BOOL res;
res = GetKeyboardState(kstate);
ok(res, "GetKeyboardState failed.\n");
kstate[vk] &= ~0x80;
res = SetKeyboardState(kstate);
ok(res, "SetKeyboardState failed.\n");
}
static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LONG defwndproc_counter = 0;
@ -2356,7 +2380,6 @@ static void test_multiselect(void)
int i, j;
static const int items=5;
DWORD item_count;
BYTE kstate[256];
select_task task;
LONG_PTR style;
LVITEMA item;
@ -2423,10 +2446,7 @@ static void test_multiselect(void)
selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
ok(selected_count == 1, "expected 1, got %ld\n", selected_count);
/* Set SHIFT key pressed */
GetKeyboardState(kstate);
kstate[VK_SHIFT]=0x80;
SetKeyboardState(kstate);
hold_key(VK_SHIFT);
for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
@ -2441,10 +2461,7 @@ static void test_multiselect(void)
"Failed multiple selection %s. There should be %ld selected items (is %ld)\n",
task.descr, item_count, selected_count);
/* Set SHIFT key released */
GetKeyboardState(kstate);
kstate[VK_SHIFT]=0x00;
SetKeyboardState(kstate);
release_key(VK_SHIFT);
}
DestroyWindow(hwnd);