gpt4 book ai didi

java - 可读的击键

转载 作者:行者123 更新时间:2023-11-30 08:59:36 26 4
gpt4 key购买 nike

除了手动解析外,Java 是否有任何默认方式将 KeyStroke 转换为可读的 String

KeyStroke ke = KeyStroke.getKeyStroke("ctrl released 1");
System.out.println(ke.toString())

Print result:
ctrl released 1

Expected:
Ctrl+1

最佳答案

来自 Java Swing API:

KeyStroke accelerator =  b.getAccelerator();
String acceleratorText = "";
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+";
}
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
}

@mKorbel,你说它不是默认值的一部分是错误的和毫无根据的

关于java - 可读的击键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27151177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com