1 /*
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 #include "awt.h"
27 #include "awt_Toolkit.h"
28 #include "awt_Component.h"
29 #include "awt_Robot.h"
30 #include "sun_awt_windows_WRobotPeer.h"
31 #include "java_awt_event_InputEvent.h"
32 #include <winuser.h>
33
34 AwtRobot::AwtRobot( jobject peer )
35 {
36 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
37 m_peerObject = env->NewWeakGlobalRef(peer);
38 JNU_CHECK_EXCEPTION(env);
39 JNI_SET_PDATA(peer, this);
40 }
41
42 AwtRobot::~AwtRobot()
43 {
44 }
45
46 #ifndef SPI_GETMOUSESPEED
47 #define SPI_GETMOUSESPEED 112
48 #endif
49
50 #ifndef SPI_SETMOUSESPEED
51 #define SPI_SETMOUSESPEED 113
52 #endif
53
54 void AwtRobot::MouseMove( jint x, jint y)
55 {
56 // Fix for Bug 4288230. See Q193003 from MSDN.
57 int oldAccel[3], newAccel[3];
58 INT_PTR oldSpeed, newSpeed;
59 BOOL bResult;
60
61 // The following values set mouse ballistics to 1 mickey/pixel.
62 newAccel[0] = 0;
63 newAccel[1] = 0;
64 newAccel[2] = 0;
65 newSpeed = 10;
66
67 // Save the Current Mouse Acceleration Constants
68 bResult = SystemParametersInfo(SPI_GETMOUSE,0,oldAccel,0);
69 bResult = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &oldSpeed,0);
70 // Set the new Mouse Acceleration Constants (Disabled).
71 bResult = SystemParametersInfo(SPI_SETMOUSE,0,newAccel,SPIF_SENDCHANGE);
72 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0,
73 // 4504963: Though the third argument to SystemParameterInfo is
74 // declared as a PVOID, as of Windows 2000 it is apparently
75 // interpreted as an int. (The MSDN docs for SPI_SETMOUSESPEED
76 // say that it's an integer between 1 and 20, the default being
77 // 10). Instead of passing the @ of the desired value, the
78 // value itself is now passed, cast as a PVOID so as to
79 // compile. -bchristi 10/02/2001
80 (PVOID)newSpeed,
81 SPIF_SENDCHANGE);
82
83 int primaryIndex = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
84 Devices::InstanceAccess devices;
85 AwtWin32GraphicsDevice *device = devices->GetDevice(primaryIndex);
86
87 x = (device == NULL) ? x : device->ScaleUpX(x);
88 y = (device == NULL) ? y : device->ScaleUpY(y);
89
90 POINT curPos;
91 ::GetCursorPos(&curPos);
92 x -= curPos.x;
93 y -= curPos.y;
94
95 mouse_event(MOUSEEVENTF_MOVE,x,y,0,0);
96 // Move the cursor to the desired coordinates.
97
98 // Restore the old Mouse Acceleration Constants.
99 bResult = SystemParametersInfo(SPI_SETMOUSE,0, oldAccel, SPIF_SENDCHANGE);
100 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)oldSpeed,
101 SPIF_SENDCHANGE);
102 }
103
104 void AwtRobot::MousePress( jint buttonMask )
105 {
106 DWORD dwFlags = 0L;
107 // According to MSDN: Software Driving Software
108 // application should consider SM_SWAPBUTTON to correctly emulate user with
109 // left handed mouse setup
110 BOOL bSwap = ::GetSystemMetrics(SM_SWAPBUTTON);
111
112 if ( buttonMask & java_awt_event_InputEvent_BUTTON1_MASK ||
113 buttonMask & java_awt_event_InputEvent_BUTTON1_DOWN_MASK)
114 {
115 dwFlags |= !bSwap ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN;
116 }
117
118 if ( buttonMask & java_awt_event_InputEvent_BUTTON3_MASK ||
119 buttonMask & java_awt_event_InputEvent_BUTTON3_DOWN_MASK)
120 {
121 dwFlags |= !bSwap ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN;
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 #include "awt.h"
27 #include "awt_Toolkit.h"
28 #include "awt_Component.h"
29 #include "awt_Robot.h"
30 #include "sun_awt_windows_WRobotPeer.h"
31 #include "java_awt_event_InputEvent.h"
32 #include <winuser.h>
33
34 AwtRobot::AwtRobot( jobject peer )
35 {
36 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
37 m_peerObject = env->NewWeakGlobalRef(peer);
38 JNU_CHECK_EXCEPTION(env);
39 JNI_SET_PDATA(peer, this);
40 }
41
42 AwtRobot::~AwtRobot()
43 {
44 }
45
46 static int signum(int i) {
47 // special version of signum which returns 1 when value is 0
48 return i >= 0 ? 1 : -1;
49 }
50
51 void AwtRobot::MouseMove( jint x, jint y)
52 {
53 INPUT mouseInput = {0};
54 mouseInput.type = INPUT_MOUSE;
55 mouseInput.mi.time = 0;
56 mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
57 mouseInput.mi.dx = (x * 65536 /::GetSystemMetrics(SM_CXSCREEN)) + signum(x);
58 mouseInput.mi.dy = (y * 65536 /::GetSystemMetrics(SM_CYSCREEN)) + signum(y);
59 ::SendInput(1, &mouseInput, sizeof(mouseInput));
60 }
61
62 void AwtRobot::MousePress( jint buttonMask )
63 {
64 DWORD dwFlags = 0L;
65 // According to MSDN: Software Driving Software
66 // application should consider SM_SWAPBUTTON to correctly emulate user with
67 // left handed mouse setup
68 BOOL bSwap = ::GetSystemMetrics(SM_SWAPBUTTON);
69
70 if ( buttonMask & java_awt_event_InputEvent_BUTTON1_MASK ||
71 buttonMask & java_awt_event_InputEvent_BUTTON1_DOWN_MASK)
72 {
73 dwFlags |= !bSwap ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN;
74 }
75
76 if ( buttonMask & java_awt_event_InputEvent_BUTTON3_MASK ||
77 buttonMask & java_awt_event_InputEvent_BUTTON3_DOWN_MASK)
78 {
79 dwFlags |= !bSwap ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN;
|