]>
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 /////////////////////////////////////////////////////////////////////////////
14 #if wxUSE_UIACTIONSIMULATOR
16 #include "wx/uiaction.h"
18 #include <ApplicationServices/ApplicationServices.h>
20 CGEventTapLocation tap
= kCGSessionEventTap
;
22 CGEventType
CGEventTypeForMouseButton(int button
, bool isDown
)
26 case wxMOUSE_BTN_LEFT
:
28 return kCGEventLeftMouseDown
;
30 return kCGEventLeftMouseUp
;
31 case wxMOUSE_BTN_RIGHT
:
33 return kCGEventRightMouseDown
;
35 return kCGEventRightMouseUp
;
37 // Apparently all other buttons use the constant OtherMouseDown
41 return kCGEventOtherMouseDown
;
43 return kCGEventOtherMouseUp
;
47 void SendCharCode(CGCharCode keycode
, bool isDown
)
49 CGEventRef event
= CGEventCreateKeyboardEvent(NULL
, keycode
, isDown
);
52 CGEventPost(kCGHIDEventTap
, event
);
57 bool wxUIActionSimulator::MouseDown(int button
)
61 wxGetMousePosition(&x
, &y
);
64 CGEventType type
= CGEventTypeForMouseButton(button
, true);
65 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, button
);
66 CGEventSetType(event
, type
);
70 CGEventPost(tap
, event
);
76 bool wxUIActionSimulator::MouseMove(long x
, long y
)
81 CGEventType type
= kCGEventMouseMoved
;
82 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, kCGMouseButtonLeft
);
83 CGEventSetType(event
, type
);
87 CGEventPost(tap
, event
);
94 bool wxUIActionSimulator::MouseUp(int button
)
98 wxGetMousePosition(&x
, &y
);
101 CGEventType type
= CGEventTypeForMouseButton(button
, false);
102 CGEventRef event
= CGEventCreateMouseEvent(NULL
, type
, pos
, button
);
103 CGEventSetType(event
, type
);
107 CGEventPost(tap
, event
);
114 bool wxUIActionSimulator::Key(int keycode
, bool isDown
, bool shiftDown
, bool cmdDown
, bool altDown
)
117 SendCharCode((CGCharCode
)56, true);
119 SendCharCode((CGCharCode
)58, true);
121 SendCharCode((CGCharCode
)55, true);
123 SendCharCode((CGCharCode
)keycode
, isDown
);
126 SendCharCode((CGCharCode
)56, false);
128 SendCharCode((CGCharCode
)58, false);
130 SendCharCode((CGCharCode
)55, false);
135 #endif // wxUSE_UIACTIONSIMULATOR