]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/uiaction.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/uiaction.cpp
3 // Purpose: wxUIActionSimulator implementation
4 // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
8 // Copyright: (c) Kevin Ollivier
9 // (c) 2010 Steven Lamerton
10 // (c) 2010 Vadim Zeitlin
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/wxprec.h"
16 #if wxUSE_UIACTIONSIMULATOR
18 #include "wx/uiaction.h"
19 #include "wx/window.h" //for wxCharCodeWXToMSW
20 #include "wx/msw/wrapwin.h"
25 DWORD
EventTypeForMouseButton(int button
, bool isDown
)
29 case wxMOUSE_BTN_LEFT
:
30 return isDown
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
32 case wxMOUSE_BTN_RIGHT
:
33 return isDown
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
35 case wxMOUSE_BTN_MIDDLE
:
36 return isDown
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
39 wxFAIL_MSG("Unsupported button passed in.");
44 void DoSimulateKbdEvent(DWORD vk
, bool isDown
)
46 keybd_event(vk
, 0, isDown
? 0 : KEYEVENTF_KEYUP
, 0);
49 } // anonymous namespace
51 bool wxUIActionSimulator::MouseDown(int button
)
55 mouse_event(EventTypeForMouseButton(button
, true), p
.x
, p
.y
, 0, 0);
59 bool wxUIActionSimulator::MouseMove(long x
, long y
)
61 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
62 // we need to scale our input too
63 int displayx
, displayy
, scaledx
, scaledy
;
64 wxDisplaySize(&displayx
, &displayy
);
65 scaledx
= ((float)x
/ displayx
) * 65535;
66 scaledy
= ((float)y
/ displayy
) * 65535;
67 mouse_event(MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
, scaledx
, scaledy
, 0, 0);
71 bool wxUIActionSimulator::MouseUp(int button
)
75 mouse_event(EventTypeForMouseButton(button
, false), p
.x
, p
.y
, 0, 0);
79 bool wxUIActionSimulator::DoKey(int keycode
, int modifiers
, bool isDown
)
83 if (modifiers
& wxMOD_SHIFT
)
84 DoSimulateKbdEvent(VK_SHIFT
, true);
85 if (modifiers
& wxMOD_ALT
)
86 DoSimulateKbdEvent(VK_MENU
, true);
87 if (modifiers
& wxMOD_CMD
)
88 DoSimulateKbdEvent(VK_CONTROL
, true);
91 DWORD vkkeycode
= wxCharCodeWXToMSW(keycode
);
92 keybd_event(vkkeycode
, 0, isDown
? 0 : KEYEVENTF_KEYUP
, 0);
96 if (modifiers
& wxMOD_SHIFT
)
97 DoSimulateKbdEvent(VK_SHIFT
, false);
98 if (modifiers
& wxMOD_ALT
)
99 DoSimulateKbdEvent(VK_MENU
, false);
100 if (modifiers
& wxMOD_CMD
)
101 DoSimulateKbdEvent(VK_CONTROL
, false);
107 #endif // wxUSE_UIACTIONSIMULATOR