2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include <sys/socket.h>
28 #include <netinet/in.h>
32 static SPIBoolean report_command_key_event (const AccessibleKeystroke *stroke, void *user_data);
33 static SPIBoolean report_ordinary_key_event (const AccessibleKeystroke *stroke, void *user_data);
34 static SPIBoolean report_synchronous_key_event (const AccessibleKeystroke *stroke, void *user_data);
36 static AccessibleKeystrokeListener *command_key_listener;
37 static AccessibleKeystrokeListener *ordinary_key_listener;
38 static AccessibleKeystrokeListener *synchronous_key_listener;
39 static AccessibleKeySet *command_keyset;
40 static AccessibleKeySet *async_keyset;
41 static AccessibleKeySet *sync_keyset;
44 main (int argc, char **argv)
49 /* prepare the keyboard snoopers */
50 command_key_listener = SPI_createAccessibleKeystrokeListener (report_command_key_event, NULL);
51 ordinary_key_listener = SPI_createAccessibleKeystrokeListener (report_ordinary_key_event, NULL);
52 synchronous_key_listener = SPI_createAccessibleKeystrokeListener (report_synchronous_key_event, NULL);
54 command_keyset = SPI_createAccessibleKeySet (11, "q", NULL, NULL);
55 async_keyset = SPI_createAccessibleKeySet (11, "abc", NULL, NULL);
56 sync_keyset = SPI_createAccessibleKeySet (11, "def", NULL, NULL);
58 SPI_registerAccessibleKeystrokeListener(command_key_listener,
60 SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL,
61 (unsigned long) ( SPI_KEY_PRESSED ),
62 SPI_KEYLISTENER_ALL_WINDOWS);
64 SPI_registerAccessibleKeystrokeListener(ordinary_key_listener,
66 SPI_KEYMASK_UNMODIFIED,
67 (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
68 SPI_KEYLISTENER_NOSYNC);
70 SPI_registerAccessibleKeystrokeListener(synchronous_key_listener,
72 SPI_KEYMASK_UNMODIFIED,
73 (unsigned long) ( SPI_KEY_PRESSED | SPI_KEY_RELEASED ),
74 SPI_KEYLISTENER_CANCONSUME);
78 putenv ("AT_BRIDGE_SHUTDOWN=1");
86 SPI_deregisterAccessibleKeystrokeListener (command_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
87 AccessibleKeystrokeListener_unref (command_key_listener);
88 SPI_freeAccessibleKeySet (command_keyset);
90 SPI_deregisterAccessibleKeystrokeListener (ordinary_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
91 AccessibleKeystrokeListener_unref (ordinary_key_listener);
92 SPI_freeAccessibleKeySet (async_keyset);
94 SPI_deregisterAccessibleKeystrokeListener (synchronous_key_listener, SPI_KEYMASK_ALT | SPI_KEYMASK_CONTROL);
95 AccessibleKeystrokeListener_unref (synchronous_key_listener);
96 SPI_freeAccessibleKeySet (sync_keyset);
102 is_command_key (const AccessibleKeystroke *key)
109 return TRUE; /* not reached */
116 print_key_event (const AccessibleKeystroke *key, char *prefix)
118 fprintf (stderr, "%s KeyEvent %s%c (keycode %d); string=%s; time=%lx\n",
120 (key->modifiers & SPI_KEYMASK_ALT)?"Alt-":"",
121 ((key->modifiers & SPI_KEYMASK_SHIFT)^(key->modifiers & SPI_KEYMASK_SHIFTLOCK))?
122 (char) toupper((int) key->keyID) : (char) tolower((int) key->keyID),
125 (long int) key->timestamp);
129 report_command_key_event (const AccessibleKeystroke *key, void *user_data)
131 print_key_event (key, "command");
132 return is_command_key (key);
136 report_ordinary_key_event (const AccessibleKeystroke *key, void *user_data)
138 print_key_event (key, "ordinary");
143 report_synchronous_key_event (const AccessibleKeystroke *key, void *user_data)
145 /* consume 'd' key, let others pass through */
146 print_key_event (key, "synchronous (consumable) ");
147 return ( key->keyID == 'd' ) ? TRUE : FALSE;