java 判断哪个键按下
- java 判断哪个键按下 推荐度:
- 相关推荐
java 判断哪个键按下
上面的代码只有在按下的唯一内容是控制键时才有效。如果他们有ctrl和其他一些按钮(可能)意外按下,它将无法捕获。
您可以完全检查ctrl键
// Are just the CTRL switches left on
if(evt.getModifiers() == InputEvent.CTRL_MASK) {
System.out.println("just the control key is pressed);
}模拟按下的多个键时,使用或位运算符。要模拟同时按住左键和ctrl键,请查找此项。
// Turn on all leftButton and CTRL switches
int desiredKey = InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK;检查ctrl键是否关闭时,您可以执行此操作
// If we turn off all switches not belonging to CTRL, are all the CTRL switches left on
if((evt.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
System.out.println("Control Key is pressed and perhaps other keys as well");
}您还可以检查是否按下了左按钮和ctrl掩码
// If we turn off all switches not belonging to leftButton or CTRL, are all the leftButton and CTRL switches left on
if((evt.getModifiers() & desiredKey) == desiredKey) {
System.out.println("left button and control keys are pressed and perhaps others as well");
}假设你有这个:
A | B你应该这样想。 A有一个控制面板,上面有一堆开关。 B还有一个控制面板,上面有一堆开关。 “| B”的工作是做必要的最小工作,以确保所有B的开关都打开。
假设你有这个:
A & B“& B”的工作是完成关闭任何不是B的开关所需的最少工作。
- 南宁市计算机技术专业学校,南宁电脑技术学校有哪些
- 怎么开展性能测试
- 【CocosBuilder 开发系列之一】cocos2dx使用CocosBuilder(编辑器)完成基础骨骼动画
- React:Component组件
- 综艺节目php灭灯
- Linux中mysql的重启
- 回溯法——回溯法的算法思想
- 数字化原理
- mmap。
- FPGA设计中,产生LFSR伪随机数
- 积累的VC编程小技巧之打印相关
- hashtable的解释
- SpringSecurity原理:探究SpringSecurity运作流程
- SimpleDateFormat api
- R语言实现聚类kmeans
- 统计学,机器学习,深度学习,数据挖掘的联系
- 【STM32学习笔记】(13)——外部中断详解