X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/571d991bb3232f0dcd3319dbdc9d35e5c80f4c71..4e15d1caa03346c126015019c1fdf093033ef40b:/src/msw/uiaction.cpp diff --git a/src/msw/uiaction.cpp b/src/msw/uiaction.cpp index e9128a6335..5aff359052 100644 --- a/src/msw/uiaction.cpp +++ b/src/msw/uiaction.cpp @@ -4,7 +4,7 @@ // Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin // Modified by: // Created: 2010-03-06 -// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Kevin Ollivier // (c) 2010 Steven Lamerton // (c) 2010 Vadim Zeitlin @@ -15,10 +15,17 @@ #if wxUSE_UIACTIONSIMULATOR -#include "wx/uiaction.h" +#ifndef WX_PRECOMP + #include "wx/msw/private.h" // For wxGetCursorPosMSW() +#endif +#include "wx/uiaction.h" #include "wx/msw/wrapwin.h" +#include "wx/msw/private/keyboard.h" + +#include "wx/math.h" + namespace { @@ -41,17 +48,12 @@ DWORD EventTypeForMouseButton(int button, bool isDown) } } -void DoSimulateKbdEvent(DWORD vk, bool isDown) -{ - keybd_event(vk, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0); -} - } // anonymous namespace bool wxUIActionSimulator::MouseDown(int button) { POINT p; - GetCursorPos(&p); + wxGetCursorPosMSW(&p); mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0); return true; } @@ -60,46 +62,37 @@ bool wxUIActionSimulator::MouseMove(long x, long y) { // Because MOUSEEVENTF_ABSOLUTE takes measurements scaled between 0 & 65535 // we need to scale our input too - int displayx, displayy, scaledx, scaledy; + int displayx, displayy; wxDisplaySize(&displayx, &displayy); - scaledx = ((float)x / displayx) * 65535; - scaledy = ((float)y / displayy) * 65535; + + int scaledx = ceil((float)x * 65535.0 / (displayx-1)); + int scaledy = ceil((float)y * 65535.0 / (displayy-1)); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, scaledx, scaledy, 0, 0); + return true; } bool wxUIActionSimulator::MouseUp(int button) { POINT p; - GetCursorPos(&p); + wxGetCursorPosMSW(&p); mouse_event(EventTypeForMouseButton(button, false), p.x, p.y, 0, 0); return true; } -bool wxUIActionSimulator::DoKey(int keycode, int modifiers, bool isDown) +bool +wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown) { - if (isDown) - { - if (modifiers & wxMOD_SHIFT) - DoSimulateKbdEvent(VK_SHIFT, true); - if (modifiers & wxMOD_ALT) - DoSimulateKbdEvent(VK_MENU, true); - if (modifiers & wxMOD_CMD) - DoSimulateKbdEvent(VK_CONTROL, true); - } + bool isExtended; + DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended); - DWORD vkkeycode = wxCharCodeWXToMSW(keycode); - keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0); + DWORD flags = 0; + if ( isExtended ) + flags |= KEYEVENTF_EXTENDEDKEY; + if ( !isDown ) + flags |= KEYEVENTF_KEYUP; - if (!isDown) - { - if (modifiers & wxMOD_SHIFT) - DoSimulateKbdEvent(VK_SHIFT, false); - if (modifiers & wxMOD_ALT) - DoSimulateKbdEvent(VK_MENU, false); - if (modifiers & wxMOD_CMD) - DoSimulateKbdEvent(VK_CONTROL, false); - } + keybd_event(vkkeycode, 0, flags, 0); return true; }