Re: [AD] Keyboard handling

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi Elias.

On 08/02/2009, you wrote:
> 

[Snipped questions about readkey()]

> The value returned by readkey() & 0xff is not KEY_C, but an ascii code
> of 3. A press of the "c" key is returned as ('c' + (KEY_C * 256)). If
> the shift key is pressed, it would be ('C' + (KEY_C * 256)). With the
> control key it would be (3 + (KEY_C * 256)).
>
> Under Windows and Linux, pressing Ctrl+C already produces an unicode
> code of 3, just as pressing Shift+C produces 'C', so those drivers
> don't do anything special for it. The OSX driver does this:
>
>       if (modifiers & NSAlternateKeyMask)
>          _handle_key_press(0, scancode);
>       else {
>          if ((modifiers & NSControlKeyMask) && (isalpha(character)))
>             _handle_key_press(tolower(character) - 'a' + 1, scancode);
>    else
>             _handle_key_press(character, scancode);
>       }
>
> So, yes, for Alt+key, Allegro expects ASCII 0, for Control+a..z it
> expects 1..26, and else just the ASCII code.

Ok, this is the missing bit of information I was looking for.  I wasn't
converting the ASCII character to a position in the alphabet when control
was pressed, as I was expecting Allegro to do it.  I was looking at the
Linux source but somehow missed this.  All return values from readkey() now
work as documented!

I don't know how A5 works but may I suggest that the keyboard driver reports
the modifier (shift, ctrl etc) state and scancodes to Allegro, which keeps
state and takes care of special keypresses such as ctrl and alt?  Letting
the driver do it is just one more thing that a porter needs to do and he
might not know that it actually needs to be done (such as in my case where
one of my beta testers was complaining that a game he had ported would not
let him type capitals).

Anyway, thanks for the help!

-- 
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/