X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/371412145fdcff75d46401eb7fcffdc047f195cb..270bae200da5680a55b3f5eced49a9d32d49c80f:/src/msw/uiaction.cpp diff --git a/src/msw/uiaction.cpp b/src/msw/uiaction.cpp index d8f498cbd8..5aff359052 100644 --- a/src/msw/uiaction.cpp +++ b/src/msw/uiaction.cpp @@ -15,10 +15,17 @@ #if wxUSE_UIACTIONSIMULATOR +#ifndef WX_PRECOMP + #include "wx/msw/private.h" // For wxGetCursorPosMSW() +#endif + #include "wx/uiaction.h" -#include "wx/window.h" //for wxCharCodeWXToMSW #include "wx/msw/wrapwin.h" +#include "wx/msw/private/keyboard.h" + +#include "wx/math.h" + namespace { @@ -46,7 +53,7 @@ DWORD EventTypeForMouseButton(int button, bool isDown) bool wxUIActionSimulator::MouseDown(int button) { POINT p; - GetCursorPos(&p); + wxGetCursorPosMSW(&p); mouse_event(EventTypeForMouseButton(button, true), p.x, p.y, 0, 0); return true; } @@ -55,18 +62,20 @@ 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; } @@ -74,8 +83,16 @@ bool wxUIActionSimulator::MouseUp(int button) bool wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown) { - DWORD vkkeycode = wxCharCodeWXToMSW(keycode); - keybd_event(vkkeycode, 0, isDown ? 0 : KEYEVENTF_KEYUP, 0); + bool isExtended; + DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended); + + DWORD flags = 0; + if ( isExtended ) + flags |= KEYEVENTF_EXTENDEDKEY; + if ( !isDown ) + flags |= KEYEVENTF_KEYUP; + + keybd_event(vkkeycode, 0, flags, 0); return true; }