SDL 物理键码和 SDL 虚拟键码有什么区别?
What is the difference between an SDL physical key code and an SDL virtual key code?
结构 SDL_Keysym
有 SDL_Scancode
和 SDL_Keycode
成员。它们之间有什么区别?该文档并没有真正为我清除它。我都试过了,他们似乎做同样的事情。
参见the SDL documentation。 Scancodes 表示按键的物理位置,仿照标准 QWERTY 键盘,而 Keycodes 是通过按键获得的字符。
在 AZERTY 键盘上,按 A 将发出 'Q'
扫描码和 'a'
键码。
通常,scancodes are the true values emitted by the keyboard (hardware) to the OS while keycode is what the OS/library maps it to based on the chosen layout. The layout decides the mapping between scancode to some virtual key code. It is part of the operating system's settings. Here, by layout, I mean the functional layout; there're also mechanical and visual layouts. Read more about keyboard layouts in Wikipedia. The concept of scan code and virtual key is explained better MSDN 中有插图。
但是,SDL 使用 scancode 表示不同的含义:美国 QWERTY 键盘中键的扫描码,其位置与所讨论的相同。这是基于其位置表示密钥的独立于设备的方式。它被埋在 SDL's manual 中一个不寻常的位置:
Scancodes are meant to be layout-independent. Think of this as "the user pressed the Q key as it would be on a US QWERTY keyboard" regardless of whether this is actually a European keyboard or a Dvorak keyboard or whatever. The scancode is always the same key position.
Keycodes are meant to be layout-dependent. Think of this as "the user pressed the key that is labelled 'Q' on a specific keyboard."
In example, if you pressed the key that's two keys to the right of CAPS LOCK on a US QWERTY keyboard, it'll report a scancode of SDL_SCANCODE_S and a keycode of SDLK_S. The same key on a Dvorak keyboard, will report a scancode of SDL_SCANCODE_S and a keycode of SDLK_O.
在上面的引用中,手册中的布局是指功能布局。关于键盘的手册main part在这个问题上有点简短:
SDL_Scancode values are used to represent the physical location of a keyboard key on the keyboard.
SDL_Keycode values are mapped to the current layout of the keyboard and correlate to an SDL_Scancode.
Which one to use is left to the application: scancodes are suited in situations where controls are layout-dependent (eg. the "WASD" keys as left-handed arrow keys), whereas keycodes are better suited to situations where controls are character-dependent (eg. the "I" key for Inventory).
在上面的引用中,手册中的布局是指 mechanical/physical 布局。所以对于字符的控制,比如使用scancode比较好,而对于接收用户名keycode比较好
结构 SDL_Keysym
有 SDL_Scancode
和 SDL_Keycode
成员。它们之间有什么区别?该文档并没有真正为我清除它。我都试过了,他们似乎做同样的事情。
参见the SDL documentation。 Scancodes 表示按键的物理位置,仿照标准 QWERTY 键盘,而 Keycodes 是通过按键获得的字符。
在 AZERTY 键盘上,按 A 将发出 'Q'
扫描码和 'a'
键码。
通常,scancodes are the true values emitted by the keyboard (hardware) to the OS while keycode is what the OS/library maps it to based on the chosen layout. The layout decides the mapping between scancode to some virtual key code. It is part of the operating system's settings. Here, by layout, I mean the functional layout; there're also mechanical and visual layouts. Read more about keyboard layouts in Wikipedia. The concept of scan code and virtual key is explained better MSDN 中有插图。
但是,SDL 使用 scancode 表示不同的含义:美国 QWERTY 键盘中键的扫描码,其位置与所讨论的相同。这是基于其位置表示密钥的独立于设备的方式。它被埋在 SDL's manual 中一个不寻常的位置:
Scancodes are meant to be layout-independent. Think of this as "the user pressed the Q key as it would be on a US QWERTY keyboard" regardless of whether this is actually a European keyboard or a Dvorak keyboard or whatever. The scancode is always the same key position.
Keycodes are meant to be layout-dependent. Think of this as "the user pressed the key that is labelled 'Q' on a specific keyboard."
In example, if you pressed the key that's two keys to the right of CAPS LOCK on a US QWERTY keyboard, it'll report a scancode of SDL_SCANCODE_S and a keycode of SDLK_S. The same key on a Dvorak keyboard, will report a scancode of SDL_SCANCODE_S and a keycode of SDLK_O.
在上面的引用中,手册中的布局是指功能布局。关于键盘的手册main part在这个问题上有点简短:
SDL_Scancode values are used to represent the physical location of a keyboard key on the keyboard.
SDL_Keycode values are mapped to the current layout of the keyboard and correlate to an SDL_Scancode.
Which one to use is left to the application: scancodes are suited in situations where controls are layout-dependent (eg. the "WASD" keys as left-handed arrow keys), whereas keycodes are better suited to situations where controls are character-dependent (eg. the "I" key for Inventory).
在上面的引用中,手册中的布局是指 mechanical/physical 布局。所以对于字符的控制,比如使用scancode比较好,而对于接收用户名keycode比较好