]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/uiaction_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/uiaction_osx.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier
7 // RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8 // Copyright: (c) Kevin Ollivier
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include <wx/uiaction.h>
15 #include <ApplicationServices/ApplicationServices.h>
17 CGEventTapLocation tap
= kCGSessionEventTap
;
19 CGEventType
CGEventTypeForMouseButton(int button
, bool isDown
)
23 case wxMOUSE_BTN_LEFT
:
25 return kCGEventLeftMouseDown
;
27 return kCGEventLeftMouseUp
;
28 case wxMOUSE_BTN_RIGHT
:
30 return kCGEventRightMouseDown
;
32 return kCGEventRightMouseUp
;
34 // Apparently all other buttons use the constant OtherMouseDown
38 return kCGEventOtherMouseDown
;
40 return kCGEventOtherMouseUp
;
44 void SendCharCode(CGCharCode keycode
, bool isDown
)
46 CGEventRef event
= CGEventCreateKeyboardEvent(NULL
, keycode
, isDown
);
49 CGEventPost(kCGHIDEventTap
, event
);
54 bool wxUIActionSimulator::MouseDown(int button
)
58 wxGetMousePosition(&x
, &y
);
61 CGEventType type
= CGEventTypeForMouseButton(button
, true);
62 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, button
);
63 CGEventSetType(event
, type
);
67 CGEventPost(tap
, event
);
73 bool wxUIActionSimulator::MouseMove(long x
, long y
)
78 CGEventType type
= kCGEventMouseMoved
;
79 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, kCGMouseButtonLeft
);
80 CGEventSetType(event
, type
);
84 CGEventPost(tap
, event
);
91 bool wxUIActionSimulator::MouseUp(int button
)
95 wxGetMousePosition(&x
, &y
);
98 CGEventType type
= CGEventTypeForMouseButton(button
, false);
99 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, button
);
100 CGEventSetType(event
, type
);
104 CGEventPost(tap
, event
);
111 bool wxUIActionSimulator::Key(int keycode
, bool isDown
, bool shiftDown
, bool cmdDown
, bool altDown
)
114 SendCharCode((CGCharCode
)56, true);
116 SendCharCode((CGCharCode
)58, true);
118 SendCharCode((CGCharCode
)55, true);
120 SendCharCode((CGCharCode
)keycode
, isDown
);
123 SendCharCode((CGCharCode
)56, false);
125 SendCharCode((CGCharCode
)58, false);
127 SendCharCode((CGCharCode
)55, false);