为什么在SDL2中没有与SDLK_COLON等效的扫描码?

huangapple go评论52阅读模式
英文:

Why there is no SDLK_COLON equivalent scancode in SDL2?

问题

我试图检查是否按下了冒号键,我使用的是英语键盘,这意味着冒号是 shift + ;,我的想法是读取键盘状态,然后检查扫描码的状态:

  SDL_PumpEvents();
  const uint8 *keyState = SDL_GetKeyboardState(NULL);

  printf("keystate %d\n", keyState[scancode]);

但后来我意识到有一个用于键盘小键盘冒号的扫描码 SDL_SCANCODE_KP_COLON,等同于SDLK_KP_COLON,但没有 SDLK_COLON 的扫描码(如果你想知道:我尝试了小键盘版本,但不起作用)。

所以,我想知道为什么没有 SDLK_COLON 的等效扫描码,以及如何更好地实现这个目标?

英文:

I'm trying to check if the colon key is pressed, I'm using a English keyboard which means colon is shift + ;, my though was to read the keyboard state and then check the status of the scancode:

  SDL_PumpEvents();
  const uint8 *keyState = SDL_GetKeyboardState(NULL);

  printf("keystate %d\n", keyState[scancode]);

but then I realized there is a scancode for the keypad colon SDL_SCANCODE_KP_COLON equivalent toSDLK_KP_COLON, but there is no scancode for SDLK_COLON (In case you are wondering: I tried with the keypad version and is not working).

So, I wonder why there is no equivalent scancode for SDLK_COLON and what's the best way to do this instead?

答案1

得分: 2

没有冒号扫描码,因为在美国标准键盘布局(ANSI)上没有一个键会在没有修改键的情况下产生冒号。 SDLK_COLON 存在是因为有一些键盘布局会在没有修改键的情况下产生冒号,比如法国键盘布局,其中与 SDL_SCANCODE_PERIOD(句号 . 或大于号 >)对应的键会产生冒号 : 或斜杠 /(使用Shift键)。因此,如果你在法国键盘上按下该键,你将接收到一个带有 SDL_SCANCODE_PERIODSDLK_COLON 的事件。

我猜你想知道用户是否输入了一个冒号,这与扫描码或不同键盘布局的键码无关。为此,你需要使用 SDL_TextInputEvent。请查看维基教程

或者,你可以使用 SDL_SCANCODE_SEMICOLON,检查该键对于用户来说对应的是什么,然后显示给用户,以便用户知道要按哪个键(对于法国键盘来说,它将是 ù 键)。

英文:

There is no colon scancode because there is no key on an ANSI (US) layout keyboard that produces a colon without modifiers. SDLK_COLON exists because there are layouts where a key produces a colon without modifier, like the French layout where the key corresponding to SDL_SCANCODE_PERIOD (dot . or greater-than sign >) makes a colon : or a slash / (with shift). So if you press that key on a French keyboard, you receive an event with SDL_SCANCODE_PERIOD and SDLK_COLON.

What I assume you want is to know if the user typed a colon, which has nothing to do with scancodes or even keycodes when dealing with different keyboard layouts. For that, you need a SDL_TextInputEvent. Check out the wiki's tutorial about it.

Or you could use SDL_SCANCODE_SEMICOLON, check what that key corresponds to for the user, and display that so the user knows what key to press (it would be the ù key for a French keyboard).

huangapple
  • 本文由 发表于 2023年2月14日 22:14:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定