]>
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
19 #include "wx/msw/private.h" // For wxGetCursorPosMSW()
22 #include "wx/uiaction.h"
23 #include "wx/msw/wrapwin.h"
25 #include "wx/msw/private/keyboard.h"
32 DWORD
EventTypeForMouseButton(int button
, bool isDown
)
36 case wxMOUSE_BTN_LEFT
:
37 return isDown
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
39 case wxMOUSE_BTN_RIGHT
:
40 return isDown
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
42 case wxMOUSE_BTN_MIDDLE
:
43 return isDown
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
46 wxFAIL_MSG("Unsupported button passed in.");
51 } // anonymous namespace
53 bool wxUIActionSimulator::MouseDown(int button
)
56 wxGetCursorPosMSW(&p
);
57 mouse_event(EventTypeForMouseButton(button
, true), p
.x
, p
.y
, 0, 0);
61 bool wxUIActionSimulator::MouseMove(long x
, long y
)
63 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
64 // we need to scale our input too
65 int displayx
, displayy
;
66 wxDisplaySize(&displayx
, &displayy
);
68 // Casts are safe because x and y are supposed to be less than the display
69 // size, so there is no danger of overflow.
70 DWORD scaledx
= static_cast<DWORD
>(ceil(x
* 65535.0 / (displayx
-1)));
71 DWORD scaledy
= static_cast<DWORD
>(ceil(y
* 65535.0 / (displayy
-1)));
72 mouse_event(MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
, scaledx
, scaledy
, 0, 0);
77 bool wxUIActionSimulator::MouseUp(int button
)
80 wxGetCursorPosMSW(&p
);
81 mouse_event(EventTypeForMouseButton(button
, false), p
.x
, p
.y
, 0, 0);
86 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
89 DWORD vkkeycode
= wxMSWKeyboard::WXToVK(keycode
, &isExtended
);
93 flags
|= KEYEVENTF_EXTENDEDKEY
;
95 flags
|= KEYEVENTF_KEYUP
;
97 keybd_event(vkkeycode
, 0, flags
, 0);
102 #endif // wxUSE_UIACTIONSIMULATOR