Debian Codegraph @

gdk/win32/gdktestutils-win32.c

raw
1 /* Gtk+ testing utilities
2 * Copyright (C) 2007 Imendio AB
3 * Authors: Tim Janik
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "config.h"
19
20 #include <gdk/gdktestutils.h>
21 #include <gdk/gdkkeysyms.h>
22 #include <win32/gdkwin32.h>
23
24
25 gboolean
26 _gdk_win32_window_simulate_key (GdkWindow *window,
27 gint x,
28 gint y,
29 guint keyval,
30 GdkModifierType modifiers,
31 GdkEventType key_pressrelease)
32 {
33 gboolean success = FALSE;
34 GdkKeymapKey *keys = NULL;
35 gint n_keys = 0;
36 INPUT ip;
37 gint i;
38
39 g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS || key_pressrelease == GDK_KEY_RELEASE, FALSE);
40 g_return_val_if_fail (window != NULL, FALSE);
41
42 ip.type = INPUT_KEYBOARD;
43 ip.ki.wScan = 0;
44 ip.ki.time = 0;
45 ip.ki.dwExtraInfo = 0;
46
47 switch (key_pressrelease)
48 {
49 case GDK_KEY_PRESS:
50 ip.ki.dwFlags = 0;
51 break;
52 case GDK_KEY_RELEASE:
53 ip.ki.dwFlags = KEYEVENTF_KEYUP;
54 break;
55 default:
56 /* Not a key event. */
57 return FALSE;
58 }
59 if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), keyval, &keys, &n_keys))
60 {
61 for (i = 0; i < n_keys; i++)
62 {
63 if (key_pressrelease == GDK_KEY_PRESS)
64 {
65 /* AltGr press. */
66 if (keys[i].group)
67 {
68 /* According to some virtualbox code I found, AltGr is
69 * simulated on win32 with LCtrl+RAlt */
70 ip.ki.wVk = VK_CONTROL;
71 SendInput(1, &ip, sizeof(INPUT));
72 ip.ki.wVk = VK_MENU;
73 SendInput(1, &ip, sizeof(INPUT));
74 }
75 /* Shift press. */
76 if (keys[i].level || (modifiers & GDK_SHIFT_MASK))
77 {
78 ip.ki.wVk = VK_SHIFT;
79 SendInput(1, &ip, sizeof(INPUT));
80 }
81 }
82
83 /* Key pressed/released. */
84 ip.ki.wVk = keys[i].keycode;
85 SendInput(1, &ip, sizeof(INPUT));
86
87 if (key_pressrelease == GDK_KEY_RELEASE)
88 {
89 /* Shift release. */
90 if (keys[i].level || (modifiers & GDK_SHIFT_MASK))
91 {
92 ip.ki.wVk = VK_SHIFT;
93 SendInput(1, &ip, sizeof(INPUT));
94 }
95 /* AltrGr release. */
96 if (keys[i].group)
97 {
98 ip.ki.wVk = VK_MENU;
99 SendInput(1, &ip, sizeof(INPUT));
100 ip.ki.wVk = VK_CONTROL;
101 SendInput(1, &ip, sizeof(INPUT));
102 }
103 }
104
105 /* No need to loop for alternative keycodes. We want only one
106 * key generated. */
107 success = TRUE;
108 break;
109 }
110 g_free (keys);
111 }
112 return success;
113 }
114
115 gboolean
116 _gdk_win32_window_simulate_button (GdkWindow *window,
117 gint x,
118 gint y,
119 guint button, /*1..3*/
120 GdkModifierType modifiers,
121 GdkEventType button_pressrelease)
122 {
123 g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
124 g_return_val_if_fail (window != NULL, FALSE);
125
126 return FALSE;
127 }