1 |
|
# Orca |
2 |
|
# |
3 |
|
# Copyright 2005-2006 Sun Microsystems Inc. |
4 |
|
# |
5 |
|
# This library is free software; you can redistribute it and/or |
6 |
|
# modify it under the terms of the GNU Library 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 |
|
# Library General Public License for more details. |
14 |
|
# |
15 |
|
# You should have received a copy of the GNU Library General Public |
16 |
|
# License along with this library; if not, write to the |
17 |
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
|
# Boston, MA 02111-1307, USA. |
19 |
|
|
20 |
1 |
"""Provides support for synthesizing keyboard and mouse events.""" |
21 |
|
|
22 |
1 |
__id__ = "$Id: eventsynthesizer.py 1533 2006-10-06 07:59:04Z richb $" |
23 |
1 |
__version__ = "$Revision: 1533 $" |
24 |
1 |
__date__ = "$Date: 2006-10-06 03:59:04 -0400 (Fri, 06 Oct 2006) $" |
25 |
1 |
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc." |
26 |
1 |
__license__ = "LGPL" |
27 |
|
|
28 |
1 |
import atspi |
29 |
1 |
import debug |
30 |
|
|
31 |
1 |
def generateMouseEvent(x, y, eventName): |
32 |
|
"""Synthesize a mouse event at a specific screen coordinate. |
33 |
|
Most AT clients should use the #AccessibleAction interface when |
34 |
|
tempted to generate mouse events, rather than this method. |
35 |
|
|
36 |
|
Event names: b1p = button 1 press; b2r = button 2 release; |
37 |
|
b3c = button 3 click; b2d = button 2 double-click; |
38 |
|
abs = absolute motion; rel = relative motion. |
39 |
|
|
40 |
|
Arguments: |
41 |
|
- x: the x screen coordinate |
42 |
|
- y: the y screen coordinate |
43 |
|
- eventName: the event name string (as described above) |
44 |
|
""" |
45 |
|
|
46 |
0 |
debug.println(debug.LEVEL_FINER, |
47 |
0 |
"SYNTHESIZING MOUSE EVENT: (%d, %d) %s"\ |
48 |
0 |
% (x, y, eventName)) |
49 |
|
|
50 |
0 |
d = atspi.Registry().registry.getDeviceEventController() |
51 |
0 |
d.generateMouseEvent(x, y, eventName) |
52 |
|
|
53 |
1 |
def clickObject(obj, button): |
54 |
|
"""Performs a button click on the given Accessible. |
55 |
|
|
56 |
|
Arguments: |
57 |
|
- obj: the Accessible |
58 |
|
- button: an integer representing the mouse button number |
59 |
|
""" |
60 |
|
|
61 |
0 |
extents = obj.extents |
62 |
0 |
x = extents.x + extents.width/2 |
63 |
0 |
y = extents.y + extents.height/2 |
64 |
0 |
generateMouseEvent(x, y, "b%dc" % button) |
65 |
|
|
66 |
1 |
def clickPoint(x, y, button): |
67 |
|
"""Performs a button click on the given point. |
68 |
|
|
69 |
|
Arguments: |
70 |
|
- obj: the Accessible |
71 |
|
- x, y: the point |
72 |
|
- button: an integer representing the mouse button number |
73 |
|
""" |
74 |
|
|
75 |
0 |
generateMouseEvent(x, y, "b%dc" % button) |
76 |
|
|
77 |
1 |
def generateKeyboardEvent(keycode, keystring, type): |
78 |
|
"""Generates a keyboard event. |
79 |
|
|
80 |
|
Arguments: |
81 |
|
- keyval: a long integer indicating the keycode or keysym of the key event |
82 |
|
being synthesized. |
83 |
|
- keystring: an (optional) UTF-8 string which, if keyval is NULL, |
84 |
|
indicates a 'composed' keyboard input string which is |
85 |
|
being synthesized; this type of keyboard event synthesis does |
86 |
|
not emulate hardware keypresses but injects the string |
87 |
|
as though a composing input method (such as XIM) were used. |
88 |
|
- type: an AccessibleKeySynthType flag indicating whether keyval |
89 |
|
is to be interpreted as a keysym rather than a keycode |
90 |
|
(atspi.Accessibility.KEY_SYM), or whether to synthesize |
91 |
|
KEY_PRESS, KEY_RELEASE, or both (KEY_PRESSRELEASE). |
92 |
|
""" |
93 |
|
|
94 |
0 |
d = atspi.Registry().registry.getDeviceEventController() |
95 |
0 |
d.generateKeyboardEvent(keycode, keystring, type) |