< prev index next >
src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp
Print this page
@@ -297,27 +297,52 @@
::DeleteDC(hdcScreen);
}
void AwtRobot::KeyPress( jint jkey )
{
- DoKeyEvent(jkey, 0); // no flags means key down
+ DoKeyEvent(jkey, 0, false); // no flags means key down
}
void AwtRobot::KeyRelease( jint jkey )
{
- DoKeyEvent(jkey, KEYEVENTF_KEYUP);
+ DoKeyEvent(jkey, KEYEVENTF_KEYUP, false);
}
-void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags )
+void AwtRobot::KeyPressUnicode( jint unicodeKey )
+{
+ DoKeyEvent(unicodeKey, 0, true); // no flags means key down
+}
+
+void AwtRobot::KeyReleaseUnicode( jint unicodeKey )
+{
+ DoKeyEvent(unicodeKey, KEYEVENTF_KEYUP, true);
+}
+
+void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags, BOOL isUnicode )
{
UINT vkey;
UINT modifiers;
UINT scancode;
JNIEnv * env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
+ if(isUnicode) {
+ /*
+ HandleUnicodeKeys() returns the status of the SendInput()
+ which returns 0 if there is a fail else non-zero.
+ The status 0 tells that the SendInput() in unable to interpret
+ the supplied input upon which the illegal argument exception
+ would be raised.
+ */
+ if(!HandleUnicodeKeys(jkey, dwFlags)) {
+ // no equivalent Windows key found for given unicode key
+ JNU_ThrowIllegalArgumentException(env, "Invalid unicode key");
+ }
+ }
+ else {
// convert Java key into Windows key (and modifiers too)
AwtComponent::JavaKeyToWindowsKey(jkey, &vkey, &modifiers);
+
if (vkey == 0) {
// no equivalent Windows key found for given Java keycode
JNU_ThrowIllegalArgumentException(env, "Invalid key code");
} else {
// get the scancode from the virtual key
@@ -335,10 +360,22 @@
vkey == VK_DOWN) {
dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
keybd_event(vkey, scancode, dwFlags, 0);
}
+ }
+}
+
+UINT AwtRobot::HandleUnicodeKeys(jint unicodeKey, DWORD dwFlags)
+{
+ NSWinInput::INPUT ip;
+ ip.type = 1; //INPUT_KEYBOARD;
+ ip.ki.wVk = 0;
+ ip.ki.wScan = unicodeKey;
+ ip.ki.dwFlags = (DWORD)(dwFlags | 4); //KEYEVENTF_UNICODE(4)
+ ip.ki.dwExtraInfo = 0;
+ return SendInput(1, (LPINPUT)&ip, sizeof(INPUT));
}
//
// utility function to get the C++ object from the Java one
//
@@ -442,5 +479,26 @@
AwtRobot::GetRobot(self)->KeyRelease(javakey);
CATCH_BAD_ALLOC;
}
+
+JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_keyPressUnicode(
+ JNIEnv *, jobject self, jint javakey )
+{
+ TRY;
+
+ AwtRobot::GetRobot(self)->KeyPressUnicode(javakey);
+
+ CATCH_BAD_ALLOC;
+}
+
+JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_keyReleaseUnicode(
+ JNIEnv *, jobject self, jint javakey )
+{
+ TRY;
+
+ AwtRobot::GetRobot(self)->KeyReleaseUnicode(javakey);
+
+ CATCH_BAD_ALLOC;
+}
+
< prev index next >