2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
28 #include <glib-object.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
34 #include <X11/keysymdef.h>
38 static SPIBoolean report_keypad_key_event (const AccessibleKeystroke *stroke, void *user_data);
40 static short *get_keypad_keycodes (void);
42 static AccessibleKeystrokeListener *keypad_key_listener;
43 static AccessibleKeySet *keypad_keyset;
45 static Display *get_display (void);
48 main (int argc, char **argv)
50 SPIBoolean retval = FALSE;
54 gdk_init (&argc, &argv); /*
55 * needed in this test program only
56 * because we are calling GDK_DISPLAY()
59 /* prepare the keyboard snoopers */
60 keypad_key_listener = SPI_createAccessibleKeystrokeListener (report_keypad_key_event, NULL);
61 keypad_keyset = SPI_createAccessibleKeySet (16, NULL, get_keypad_keycodes (), NULL);
63 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
65 SPI_KEYMASK_UNMODIFIED,
66 (unsigned long) ( SPI_KEY_PRESSED |
68 SPI_KEYLISTENER_ALL_WINDOWS);
69 fprintf (stderr, "Keypad key registry: result %s\n", retval ? "succeeded" :
72 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
75 (unsigned long) ( SPI_KEY_PRESSED |
77 SPI_KEYLISTENER_ALL_WINDOWS);
79 fprintf (stderr, "Shift-Keypad key registry: result %s\n", retval ? "succeeded" :
82 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
85 (unsigned long) ( SPI_KEY_PRESSED |
87 SPI_KEYLISTENER_ALL_WINDOWS);
89 fprintf (stderr, "Mod2-Keypad key registry: result %s\n", retval ? "succeeded" :
92 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
95 (unsigned long) ( SPI_KEY_PRESSED |
97 SPI_KEYLISTENER_ALL_WINDOWS);
99 fprintf (stderr, "Mod3-Keypad key registry: result %s\n", retval ? "succeeded" :
102 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
104 SPI_KEYMASK_MOD2 | SPI_KEYMASK_SHIFT,
105 (unsigned long) ( SPI_KEY_PRESSED |
107 SPI_KEYLISTENER_ALL_WINDOWS);
109 fprintf (stderr, "Mod2-Shift-Keypad key registry: result %s\n", retval ? "succeeded" :
112 retval = SPI_registerAccessibleKeystrokeListener(keypad_key_listener,
114 SPI_KEYMASK_MOD3 | SPI_KEYMASK_SHIFT,
115 (unsigned long) ( SPI_KEY_PRESSED |
117 SPI_KEYLISTENER_ALL_WINDOWS);
119 fprintf (stderr, "Mod3-Shift-Keypad key registry: result %s\n", retval ? "succeeded" :
124 putenv ("AT_BRIDGE_SHUTDOWN=1");
132 return GDK_DISPLAY ();
136 get_keypad_keycodes (void)
138 short *keycodes = (short *) g_new0 (short *, 16);
141 keycodes [0] = XKeysymToKeycode (get_display (), XK_KP_0);
142 keycodes [1] = XKeysymToKeycode (get_display (), XK_KP_1);
143 keycodes [2] = XKeysymToKeycode (get_display (), XK_KP_2);
144 keycodes [3] = XKeysymToKeycode (get_display (), XK_KP_3);
145 keycodes [4] = XKeysymToKeycode (get_display (), XK_KP_4);
146 keycodes [5] = XKeysymToKeycode (get_display (), XK_KP_5);
147 keycodes [6] = XKeysymToKeycode (get_display (), XK_KP_6);
148 keycodes [7] = XKeysymToKeycode (get_display (), XK_KP_7);
149 keycodes [8] = XKeysymToKeycode (get_display (), XK_KP_8);
150 keycodes [9] = XKeysymToKeycode (get_display (), XK_KP_9);
151 keycodes [10] = XKeysymToKeycode (get_display (), XK_KP_Divide);
152 keycodes [11] = XKeysymToKeycode (get_display (), XK_KP_Multiply);
153 keycodes [12] = XKeysymToKeycode (get_display (), XK_KP_Add);
154 keycodes [13] = XKeysymToKeycode (get_display (), XK_KP_Subtract);
155 keycodes [14] = XKeysymToKeycode (get_display (), XK_KP_Decimal);
156 keycodes [15] = XKeysymToKeycode (get_display (), XK_KP_Enter);
158 for (i = 0; i < 16; ++i)
160 fprintf (stderr, "keycode[%d] = %d\n", i, (int) keycodes[i]);
166 print_key_event (const AccessibleKeystroke *key, char *prefix)
168 fprintf (stderr, "%s KeyEvent %s%c [keysym 0x%x] (keycode %d); string=%s; time=%lx\n",
170 (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
171 ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
172 (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID),
176 (long int) key->timestamp);
180 report_keypad_key_event (const AccessibleKeystroke *key, void *user_data)
182 print_key_event (key, "keypad");