]>
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"
26 DWORD
EventTypeForMouseButton(int button
, bool isDown
)
30 case wxMOUSE_BTN_LEFT
:
31 return isDown
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_LEFTUP
;
33 case wxMOUSE_BTN_RIGHT
:
34 return isDown
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_RIGHTUP
;
36 case wxMOUSE_BTN_MIDDLE
:
37 return isDown
? MOUSEEVENTF_MIDDLEDOWN
: MOUSEEVENTF_MIDDLEUP
;
40 wxFAIL_MSG("Unsupported button passed in.");
45 } // anonymous namespace
47 bool wxUIActionSimulator::MouseDown(int button
)
51 mouse_event(EventTypeForMouseButton(button
, true), p
.x
, p
.y
, 0, 0);
55 bool wxUIActionSimulator::MouseMove(long x
, long y
)
57 // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535
58 // we need to scale our input too
59 int displayx
, displayy
, scaledx
, scaledy
;
60 wxDisplaySize(&displayx
, &displayy
);
61 scaledx
= ((float)x
/ displayx
) * 65535;
62 scaledy
= ((float)y
/ displayy
) * 65535;
63 mouse_event(MOUSEEVENTF_ABSOLUTE
| MOUSEEVENTF_MOVE
, scaledx
, scaledy
, 0, 0);
67 bool wxUIActionSimulator::MouseUp(int button
)
71 mouse_event(EventTypeForMouseButton(button
, false), p
.x
, p
.y
, 0, 0);
76 wxUIActionSimulator::DoKey(int keycode
, int WXUNUSED(modifiers
), bool isDown
)
79 DWORD vkkeycode
= wxMSWKeyboard::WXToVK(keycode
, &isExtended
);
83 flags
|= KEYEVENTF_EXTENDEDKEY
;
85 flags
|= KEYEVENTF_KEYUP
;
87 keybd_event(vkkeycode
, 0, flags
, 0);
92 #endif // wxUSE_UIACTIONSIMULATOR