]>
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
7 // Copyright: (c) Kevin Ollivier
8 // (c) 2010 Steven Lamerton
9 // (c) 2010 Vadim Zeitlin
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/wxprec.h"
15 #if wxUSE_UIACTIONSIMULATOR
18 #include "wx/msw/private.h" // For wxGetCursorPosMSW()
21 #include "wx/uiaction.h"
22 #include "wx/msw/wrapwin.h"
24 #include "wx/msw/private/keyboard.h"
31 DWORD
EventTypeForMouseButton(int button
, bool isDown
)
35 case wxMOUSE_BTN_LEFT
:
36 return isDown
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
38 case wxMOUSE_BTN_RIGHT
:
39 return isDown
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
41 case wxMOUSE_BTN_MIDDLE
:
42 return isDown
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
45 wxFAIL_MSG("Unsupported button passed in.");
50 } // anonymous namespace
52 bool wxUIActionSimulator::MouseDown(int button
)
55 wxGetCursorPosMSW(&p
);
56 mouse_event(EventTypeForMouseButton(button
, true), p
.x
, p
.y
, 0, 0);
60 bool wxUIActionSimulator::MouseMove(long x
, long y
)
62 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
63 // we need to scale our input too
64 int displayx
, displayy
;
65 wxDisplaySize(&displayx
, &displayy
);
67 // Casts are safe because x and y are supposed to be less than the display
68 // size, so there is no danger of overflow.
69 DWORD scaledx
= static_cast<DWORD
>(ceil(x
* 65535.0 / (displayx
-1)));
70 DWORD scaledy
= static_cast<DWORD
>(ceil(y
* 65535.0 / (displayy
-1)));
71 mouse_event(MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
, scaledx
, scaledy
, 0, 0);
76 bool wxUIActionSimulator::MouseUp(int button
)
79 wxGetCursorPosMSW(&p
);
80 mouse_event(EventTypeForMouseButton(button
, false), p
.x
, p
.y
, 0, 0);
85 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
88 DWORD vkkeycode
= wxMSWKeyboard::WXToVK(keycode
, &isExtended
);
92 flags
|= KEYEVENTF_EXTENDEDKEY
;
94 flags
|= KEYEVENTF_KEYUP
;
96 keybd_event(vkkeycode
, 0, flags
, 0);
101 #endif // wxUSE_UIACTIONSIMULATOR