Pergunta

I want to know what end-users have pressed, so I used getch() .

If users pressed Right, I could get 0xE0 0x4D.

If users pressed Ctrl+Right, I could get 0xE0 0x47.

If users pressed Shift+Right, I could get 0xE0 0x4D.

The return of Right and Shift+Right from getch() are the same, so how could I know what end-users have pressed?

Foi útil?

Solução

According to the values you report for the pressed keys, I assume you are using some MS-DOS environment and compiler and you have put keyboard input to scancode mode. If so, you should know all driver logic details. Particularly, holding Shift is reported with a corresponding scancode. This table reports two shifts have 2Ah and 36h, so, you should take both into account, keeping an internal table of pressed modifiers, as well as for two Ctrls, two Alts, Caps, etc.

(Is it really the thing you want here? Scancodes are very low level beast.)

UPDATE: I forgot to specify that navigation keys handling is specific in the keyboard itself. For the numeric block, it depends on NumLock state. For the additional arrow/navigation block, it generally acts as the numeric block with NumLock off, but there are subtle differences. There are good descriptions in details, as this one, and care shall be taken to reflect e.g. difference between set 1 and translated set 2 (the latter is the currently used with PS/2). PS/2 emulation for USB keyboard in BIOS could add its own specifics. Generally all this isn't complex but cumbersome and requires many legacy issues knowledge.

Outras dicas

A simple getch is not able no handle all keyboard events. It just won´t work that way you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top