]>
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/msw/wrapwin.h"
21 #include "wx/msw/private/keyboard.h"
28 DWORD
EventTypeForMouseButton(int button
, bool isDown
)
32 case wxMOUSE_BTN_LEFT
:
33 return isDown
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
35 case wxMOUSE_BTN_RIGHT
:
36 return isDown
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
38 case wxMOUSE_BTN_MIDDLE
:
39 return isDown
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
42 wxFAIL_MSG("Unsupported button passed in.");
47 } // anonymous namespace
49 bool wxUIActionSimulator::MouseDown(int button
)
53 mouse_event(EventTypeForMouseButton(button
, true), p
.x
, p
.y
, 0, 0);
57 bool wxUIActionSimulator::MouseMove(long x
, long y
)
59 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
60 // we need to scale our input too
61 int displayx
, displayy
;
62 wxDisplaySize(&displayx
, &displayy
);
64 int scaledx
= wxRound(((float)x
/ displayx
) * 65535);
65 int scaledy
= wxRound(((float)y
/ displayy
) * 65535);
66 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);
80 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
83 DWORD vkkeycode
= wxMSWKeyboard::WXToVK(keycode
, &isExtended
);
87 flags
|= KEYEVENTF_EXTENDEDKEY
;
89 flags
|= KEYEVENTF_KEYUP
;
91 keybd_event(vkkeycode
, 0, flags
, 0);
96 #endif // wxUSE_UIACTIONSIMULATOR