gpt4 book ai didi

JavaFX - 获取非 ASCII 字符的 KeyEvent

转载 作者:太空宇宙 更新时间:2023-11-04 14:28:44 25 4
gpt4 key购买 nike

在 JavaFX(实际上是 ScalaFX)应用程序中,我希望允许用户通过一系列键盘按键调用命令。无论当前键盘布局(语言)如何,这些命令都应该有效。例如,用户可能正在输入泰语 (ภาษา),然后想通过按“Escape”和“S”(或“:”然后“w”,vim 风格)进行保存。

我发现 KeyEvents 为非英语(非 ASCII?)字符提供未定义的键代码。

这段代码:

onKeyPressed = (k: KeyEvent) => {
println("text: " + k.text + " " + "code name: " + k.code.name)
}

给出:

text: a  code name: A  
text: code name: Alt << Alt + Shift switches from English to Hebrew
text: code name: Shift
text: ש code name: Undefined

按 A 时,将语言更改为希伯来语并再次按。

如何克服这个问题?无论语言如何,我如何才能知道按下了哪个键?

类似的未回答问题:JavaFX KeyEvent and accented characters

最佳答案

getCharacter()将为您提供 KeyEvent 后面的 unicode 字符:

The unicode character associated with the key typed event. For example, char will have the value "A" for a key typed event generated by pressing SHIFT + 'a'. For key pressed and key released events, char is always CHAR_UNDEFINED.

关于JavaFX - 获取非 ASCII 字符的 KeyEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26392333/

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