Results 1 to 2 of 2

Thread: Keyboard entry

  1. #1

    Keyboard entry

    When a user presses Shift+4 on my keyboard, he expects to get the '$' character in his favourite editor. The SDL event manager, on the other hand, will return not the ascii value of '$' but rather the ascii value of '4', and the modstate will have KMOD_LSHIFT or'd into it.

    Is there a function in SDL or FreePascal or Delphi which takes an ascii value and a boolean (Shift on or off) and returns the ascii value of the shift character? How would I go about writing this function? I hope I don't have to manually construct a large lookup-table which worked something like this:

    if ascii-value = byte('5') and SHIFT then result := '%' else result = '5'
    if ascii-value = byte('6') and SHIFT then result := '^' else result = '6'
    if ascii-value = byte('7') and SHIFT then result := '&' else result = '7'
    etc etc

    What a pain in the arse! And how do I know that all keyboards have '&' above the '7' key, '^' above the '6' key, and '%' above the '5' key? There must be some easier way of doing this!
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

  2. #2

    Keyboard entry

    To answer my own question and reveal how lazy I am to RTFM, this will do the job:

    Char(event^.key.keysym.unicode)

    But you have to enable unicode support:

    SDL_EnableUNICODE(1)

    Simple solutions for simple minds.
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •