]> git.saurik.com Git - wxWidgets.git/blame - src/msw/uiaction.cpp
No code changes, fixed some typos.
[wxWidgets.git] / src / msw / uiaction.cpp
CommitLineData
a02a5cfc
KO
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/uiaction.cpp
3// Purpose: wxUIActionSimulator implementation
571d991b 4// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
a02a5cfc
KO
5// Modified by:
6// Created: 2010-03-06
5bb302a7 7// RCS-ID: $Id$
a02a5cfc 8// Copyright: (c) Kevin Ollivier
571d991b
VZ
9// (c) 2010 Steven Lamerton
10// (c) 2010 Vadim Zeitlin
a02a5cfc
KO
11// Licence: wxWindows licence
12/////////////////////////////////////////////////////////////////////////////
13
14#include "wx/wxprec.h"
15
9b7e0226 16#if wxUSE_UIACTIONSIMULATOR
a02a5cfc
KO
17
18#include "wx/uiaction.h"
9b7e0226 19#include "wx/msw/wrapwin.h"
a02a5cfc 20
0c03f52d
VZ
21#include "wx/msw/private/keyboard.h"
22
571d991b
VZ
23namespace
24{
25
a02a5cfc
KO
26DWORD EventTypeForMouseButton(int button, bool isDown)
27{
28 switch (button)
29 {
30 case wxMOUSE_BTN_LEFT:
571d991b
VZ
31 return isDown ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
32
a02a5cfc 33 case wxMOUSE_BTN_RIGHT:
571d991b
VZ
34 return isDown ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
35
a02a5cfc 36 case wxMOUSE_BTN_MIDDLE:
571d991b 37 return isDown ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
9b7e0226 38
a02a5cfc
KO
39 default:
40 wxFAIL_MSG("Unsupported button passed in.");
571d991b 41 return (DWORD)-1;
a02a5cfc
KO
42 }
43}
44
571d991b
VZ
45} // anonymous namespace
46
a02a5cfc
KO
47bool wxUIActionSimulator::MouseDown(int button)
48{
49 POINT p;
50 GetCursorPos(&p);
51 mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0);
52 return true;
53}
54
55bool wxUIActionSimulator::MouseMove(long x, long y)
9b7e0226 56{
571d991b
VZ
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);
a02a5cfc
KO
64 return true;
65}
66
67bool wxUIActionSimulator::MouseUp(int button)
68{
69 POINT p;
70 GetCursorPos(&p);
71 mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0);
72 return true;
73}
74
37141214
VZ
75bool
76wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown)
a02a5cfc 77{
2dcbc461 78 bool isExtended;
0c03f52d 79 DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended);
2dcbc461
VZ
80
81 DWORD flags = 0;
82 if ( isExtended )
83 flags |= KEYEVENTF_EXTENDEDKEY;
84 if ( !isDown )
85 flags |= KEYEVENTF_KEYUP;
86
87 keybd_event(vkkeycode, 0, flags, 0);
571d991b 88
a02a5cfc
KO
89 return true;
90}
91
9b7e0226 92#endif // wxUSE_UIACTIONSIMULATOR