< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp

Print this page




 318 void AwtRobot::KeyRelease( jint jkey )
 319 {
 320     DoKeyEvent(jkey, KEYEVENTF_KEYUP);
 321 }
 322 
 323 void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags )
 324 {
 325     UINT        vkey;
 326     UINT        modifiers;
 327     UINT        scancode;
 328     JNIEnv *    env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 329 
 330     // convert Java key into Windows key (and modifiers too)
 331     AwtComponent::JavaKeyToWindowsKey(jkey, &vkey, &modifiers);
 332     if (vkey == 0) {
 333         // no equivalent Windows key found for given Java keycode
 334         JNU_ThrowIllegalArgumentException(env, "Invalid key code");
 335     } else {
 336         // get the scancode from the virtual key
 337         scancode = ::MapVirtualKey(vkey, 0);
 338         if (vkey == VK_RMENU) {










 339             dwFlags |= KEYEVENTF_EXTENDEDKEY;
 340         }
 341         keybd_event(vkey, scancode, dwFlags, 0);
 342     }
 343 }
 344 
 345 //
 346 // utility function to get the C++ object from the Java one
 347 //
 348 // (static)
 349 AwtRobot * AwtRobot::GetRobot( jobject self )
 350 {
 351     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 352     AwtRobot * robot = (AwtRobot *)JNI_GET_PDATA(self);
 353     DASSERT( !::IsBadWritePtr( robot, sizeof(AwtRobot)));
 354     return robot;
 355 }
 356 
 357 //////////////////////////////////////////////////////////////////////////////////////////////
 358 // Native method declarations




 318 void AwtRobot::KeyRelease( jint jkey )
 319 {
 320     DoKeyEvent(jkey, KEYEVENTF_KEYUP);
 321 }
 322 
 323 void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags )
 324 {
 325     UINT        vkey;
 326     UINT        modifiers;
 327     UINT        scancode;
 328     JNIEnv *    env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 329 
 330     // convert Java key into Windows key (and modifiers too)
 331     AwtComponent::JavaKeyToWindowsKey(jkey, &vkey, &modifiers);
 332     if (vkey == 0) {
 333         // no equivalent Windows key found for given Java keycode
 334         JNU_ThrowIllegalArgumentException(env, "Invalid key code");
 335     } else {
 336         // get the scancode from the virtual key
 337         scancode = ::MapVirtualKey(vkey, 0);
 338         if (vkey == VK_RMENU ||
 339             vkey == VK_DELETE ||
 340             vkey == VK_INSERT ||
 341             vkey == VK_NEXT ||
 342             vkey == VK_PRIOR ||
 343             vkey == VK_HOME ||
 344             vkey == VK_END ||
 345             vkey == VK_LEFT ||
 346             vkey == VK_RIGHT ||
 347             vkey == VK_UP ||
 348             vkey == VK_DOWN) {
 349             dwFlags |= KEYEVENTF_EXTENDEDKEY;
 350         }
 351         keybd_event(vkey, scancode, dwFlags, 0);
 352     }
 353 }
 354 
 355 //
 356 // utility function to get the C++ object from the Java one
 357 //
 358 // (static)
 359 AwtRobot * AwtRobot::GetRobot( jobject self )
 360 {
 361     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 362     AwtRobot * robot = (AwtRobot *)JNI_GET_PDATA(self);
 363     DASSERT( !::IsBadWritePtr( robot, sizeof(AwtRobot)));
 364     return robot;
 365 }
 366 
 367 //////////////////////////////////////////////////////////////////////////////////////////////
 368 // Native method declarations


< prev index next >