如何判断按下了哪个 SHIFT 键?

How to tell which SHIFT key was pressed?(如何判断按下了哪个 SHIFT 键?)
本文介绍了如何判断按下了哪个 SHIFT 键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我的游戏中,我希望能够使用左右 shift 键来执行不同的功能.在 Java(或其他语言)中,有什么方法可以区分这两者吗?

In my game, I want to be able to use the right and left shift keys for different functions. In Java (or another language), is there any way to distinguish between those two?

KeyEvent类只有VK_SHIFT,对应左右shift键.与 ControlAltEnter 等相同.

The KeyEvent class has only VK_SHIFT, which corresponds to both left and right shift keys. Same with Control, Alt, Enter, etc.

我主要担心有人可能会用两根手指同时快速按下两个键,从而获得不公平的优势.我应该担心这个吗?

My primary concern is someone may be able to use two fingers to rapidly press both keys at the same time, gaining an unfair advantage. Should I be concerned about this?

推荐答案

我找到了一个包含 Java WebStart 示例和源代码的 Java 教程.看起来获胜者是 KeyEvent.getKeyLocation()

I found a Java tutorial that includes a Java WebStart sample and the source code. Looks like the winner is KeyEvent.getKeyLocation()

  • KeyEvent.KEY_LOCATION_STANDARD
  • KeyEvent.KEY_LOCATION_LEFT
  • KeyEvent.KEY_LOCATION_RIGHT
  • KeyEvent.KEY_LOCATION_NUMPAD
  • KeyEvent.KEY_LOCATION_UNKNOWN

参考资料:

关键监听器演示和源代码

这篇关于如何判断按下了哪个 SHIFT 键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard(使用键盘滚动其弹出列表时如何使 JComboBox 所选项目不更改)
Capturing keystrokes without focus(在没有焦点的情况下捕获击键)
How can I position a layout right above the android on-screen keyboard?(如何将布局放置在 android 屏幕键盘的正上方?)
How to check for key being held down on startup in Java(如何检查在Java中启动时按住的键)
Android - Get keyboard key press(Android - 获取键盘按键)