< prev index next >

modules/javafx.graphics/src/main/native-glass/win/Robot.cpp

Print this page


   1 /*
   2  * Copyright (c) 2011, 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


  77  * Method:    _keyPress
  78  * Signature: (I)V
  79  */
  80 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1keyPress
  81     (JNIEnv *env, jobject jrobot, jint code)
  82 {
  83     KeyEvent(env, code, true);
  84 }
  85 
  86 /*
  87  * Class:     com_sun_glass_ui_win_WinRobot
  88  * Method:    _keyRelease
  89  * Signature: (I)V
  90  */
  91 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1keyRelease
  92     (JNIEnv *env, jobject jrobot, jint code)
  93 {
  94     KeyEvent(env, code, false);
  95 }
  96 





  97 /*
  98  * Class:     com_sun_glass_ui_win_WinRobot
  99  * Method:    _mouseMove
 100  * Signature: (II)V
 101  */
 102 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1mouseMove
 103     (JNIEnv *env, jobject jrobot, jint x, jint y)
 104 {
 105     int oldAccel[3], newAccel[3];
 106     INT_PTR oldSpeed, newSpeed;
 107     BOOL bResult;
 108 
 109     jfloat fx = (jfloat) x + 0.5f;
 110     jfloat fy = (jfloat) y + 0.5f;
 111     GlassScreen::FX2Win(&fx, &fy);
 112     x = (jint) fx;
 113     y = (jint) fy;
 114 
 115     // The following values set mouse ballistics to 1 mickey/pixel.
 116     newAccel[0] = 0;
 117     newAccel[1] = 0;
 118     newAccel[2] = 0;
 119     newSpeed = 10;
 120 
 121     // Save the Current Mouse Acceleration Constants
 122     bResult = ::SystemParametersInfo(SPI_GETMOUSE, 0, oldAccel, 0);
 123     bResult = ::SystemParametersInfo(SPI_GETMOUSESPEED, 0, &oldSpeed, 0);
 124     // Set the new Mouse Acceleration Constants (Disabled).
 125     bResult = ::SystemParametersInfo(SPI_SETMOUSE, 0, newAccel, SPIF_SENDCHANGE);
 126     bResult = ::SystemParametersInfo(SPI_SETMOUSESPEED, 0,
 127             (PVOID)newSpeed,
 128             SPIF_SENDCHANGE);
 129 
 130     POINT curPos;
 131     ::GetCursorPos(&curPos);
 132     x -= curPos.x;
 133     y -= curPos.y;
 134 
 135     ::mouse_event(MOUSEEVENTF_MOVE, x, y, 0, 0);
 136     // Move the cursor to the desired coordinates.
 137 
 138     // Restore the old Mouse Acceleration Constants.
 139     bResult = ::SystemParametersInfo(SPI_SETMOUSE,0, oldAccel, SPIF_SENDCHANGE);
 140     bResult = ::SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)oldSpeed,
 141             SPIF_SENDCHANGE);
 142 }
 143 
 144 /*
 145  * Class:     com_sun_glass_ui_win_WinRobot
 146  * Method:    _getMouseX
 147  * Signature: ()I
 148  */
 149 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_win_WinRobot__1getMouseX
 150     (JNIEnv *env, jobject jrobot)
 151 {
 152     POINT curPos;
 153     ::GetCursorPos(&curPos);
 154     jfloat fx = (jfloat) curPos.x + 0.5f;
 155     jfloat fy = (jfloat) curPos.y + 0.5f;
 156     GlassScreen::Win2FX(&fx, &fy);
 157     return (jint) fx;
 158 }
 159 
 160 /*
 161  * Class:     com_sun_glass_ui_win_WinRobot


   1 /*
   2  * Copyright (c) 2011, 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


  77  * Method:    _keyPress
  78  * Signature: (I)V
  79  */
  80 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1keyPress
  81     (JNIEnv *env, jobject jrobot, jint code)
  82 {
  83     KeyEvent(env, code, true);
  84 }
  85 
  86 /*
  87  * Class:     com_sun_glass_ui_win_WinRobot
  88  * Method:    _keyRelease
  89  * Signature: (I)V
  90  */
  91 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1keyRelease
  92     (JNIEnv *env, jobject jrobot, jint code)
  93 {
  94     KeyEvent(env, code, false);
  95 }
  96 
  97 static int signum(int i) {
  98     // special version of signum which returns 1 when value is 0
  99     return i >= 0 ? 1 : -1;
 100     }
 101 
 102 /*
 103  * Class:     com_sun_glass_ui_win_WinRobot
 104  * Method:    _mouseMove
 105  * Signature: (II)V
 106  */
 107 JNIEXPORT void JNICALL Java_com_sun_glass_ui_win_WinRobot__1mouseMove
 108     (JNIEnv *env, jobject jrobot, jint x, jint y)
 109 {




 110     jfloat fx = (jfloat) x + 0.5f;
 111     jfloat fy = (jfloat) y + 0.5f;
 112     GlassScreen::FX2Win(&fx, &fy);
 113     INPUT mouseInput = {0};
 114     mouseInput.type = INPUT_MOUSE;
 115     mouseInput.mi.time = 0;
 116     mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
 117     mouseInput.mi.dx = (jint)(fx * 65535.0 / ::GetSystemMetrics(SM_CXSCREEN)) + signum((int)fx);
 118     mouseInput.mi.dy = (jint)(fy * 65535.0 / ::GetSystemMetrics(SM_CYSCREEN)) + signum((int)fy);
 119     ::SendInput(1, &mouseInput, sizeof(mouseInput));























 120 }
 121 
 122 /*
 123  * Class:     com_sun_glass_ui_win_WinRobot
 124  * Method:    _getMouseX
 125  * Signature: ()I
 126  */
 127 JNIEXPORT jint JNICALL Java_com_sun_glass_ui_win_WinRobot__1getMouseX
 128     (JNIEnv *env, jobject jrobot)
 129 {
 130     POINT curPos;
 131     ::GetCursorPos(&curPos);
 132     jfloat fx = (jfloat) curPos.x + 0.5f;
 133     jfloat fy = (jfloat) curPos.y + 0.5f;
 134     GlassScreen::Win2FX(&fx, &fy);
 135     return (jint) fx;
 136 }
 137 
 138 /*
 139  * Class:     com_sun_glass_ui_win_WinRobot


< prev index next >