在AS3中捕获大写字母

发布于 2024-11-28 18:48:54 字数 319 浏览 0 评论 0原文

好的,我知道如何捕捉常见的小写字母。我正在使用 KeyboardEvent.KEY_DOWN 并将代码与 ASCII 表进行比较,以找出按下了哪个键。现在,我也希望能够找出是否有,例如按下 SHIFT+A,但我不知道如何实现这一点。我的意思是,在我的程序中,SHIFT 和 A 是完全不同的键,彼此无关,按下时它们都会调用 KeyboardEvents。在格鲁吉亚语字母表中,某些字母是通过 SHIFT 和英文字母组合输入的,例如格鲁吉亚语键盘上的 W 表示 წ,而 SIFT+W 表示 ჭ。正如您所看到的,完全不同的字母。我希望能够同时抓住这两个方面,因为我目前正在开发格鲁吉亚语游戏。任何帮助将不胜感激。提前致谢 :-)

Okay, I know how to catch usual lowercase letters. I'm using KeyboardEvent.KEY_DOWN and compare the code to the ASCII table to find out which key was pressed. Now, I also want to be able to find out if there is, for example SHIFT+A pressed, and I have no idea how to implement this. I mean, in my program SHIFT and A are absolutely different keys which have nothing to do with each other, and they both will call KeyboardEvents when pressed. In Georgian alphabet some letters are typed by combination of SHIFT and English letters, for example W on Georgian keyboard means წ, when SIFT+W means ჭ. Absolutely different letters, as you can see. And I want to be able to catch both, coz I'm currently developing Georgian-language game. Any help will be appreciated. Thanks in advance :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

英雄似剑 2024-12-05 18:48:54

看一下 KeyEvent 类。它为您提供有关是否按下 Shift 键的信息。看这个例子:

stage.addEventListener (KeyboardEvent.KEY_DOWN, keyDownHandler);

function keyDownHandler (e:KeyboardEvent):void {
    trace("Key code: "+e.keyCode);
    trace("Ctrl status: "+e.ctrlKey);
    trace("Key location: "+e.keyLocation);
    trace("Shift key: "+e.shiftKey);
}

这是一个示例输出:

(pressing the "a" key)
Key code: 65
Ctrl status: false
Key location: 0
Shift key: false

(pressing the SHIFT first for shift+a)
Key code: 16
Ctrl status: false
Key location: 1
Shift key: true

(pressing the "a" key while still holding shift)
Key code: 65
Ctrl status: false
Key location: 0
Shift key: true

正如您所看到的,KeyboardEvent.keyCode 和 KeyboardEvent.shiftKey 的组合保存了您正在查找的信息。

Take a look at the KeyEvent class. It provides you with the infos on if the shift key was pressed or not. Look at this example:

stage.addEventListener (KeyboardEvent.KEY_DOWN, keyDownHandler);

function keyDownHandler (e:KeyboardEvent):void {
    trace("Key code: "+e.keyCode);
    trace("Ctrl status: "+e.ctrlKey);
    trace("Key location: "+e.keyLocation);
    trace("Shift key: "+e.shiftKey);
}

This is an example output:

(pressing the "a" key)
Key code: 65
Ctrl status: false
Key location: 0
Shift key: false

(pressing the SHIFT first for shift+a)
Key code: 16
Ctrl status: false
Key location: 1
Shift key: true

(pressing the "a" key while still holding shift)
Key code: 65
Ctrl status: false
Key location: 0
Shift key: true

As you can see the combination of KeyboardEvent.keyCode and KeyboardEvent.shiftKey hold the information which you are looking for.

述情 2024-12-05 18:48:54

您应该使用 KeyboardEvent.charCode (它提供了英文代码,您需要将其映射到您的格鲁吉亚键盘布局。)当大写锁定打开时,按 Shift 键可能会给出小写字母。

You should use KeyboardEvent.charCode (it gives english code, you need to map it to your Georgian keyboard layout.) Key press with shift may give lowercase letter when capslock is on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文