Results 1 to 10 of 12

Thread: Sdl/OpenGl Keyboard management

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Sdl/OpenGl Keyboard management

    Found a stumbling block when doing some work on a map editor. I am building it all from the ground up and I at some point need to specify a file to load. Thus you must type out the path & name. However, sdl which I am using at the moment to manage my events has other plans:

    Every time I hit backspace, Caps, Shift, Num and etc I get garbage data. The key registers but doesnt actually change all the keys to upercase or whatever they are supposed to be... is there either:
    a) a sdl_enablecaps/num or something I am missing
    b) a better way to manage eventd than sdl?

    cheers,
    code_glitch.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    This works for me:

    Code:
    Form1.Keypreview:=true;
    
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
    begin
      memo1.Lines.Add(key); // key will automatically be in caps/non caps
    end;

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Although I am not using delphi/lazarus here its just plain pascal.... So what units do you use to make that work? I might be able to take a look at the source and take what I need. Cheers for such a simple solution though.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4
    Is this cross platform, or could you just use the Windows API?

    User137's solution involves using Delphi's VCL etc, the units Forms and I think Standard Controls (plus the units they use, so and so forth) would be the minimum, probably overkill for what you need.

  5. #5
    Actually Lazarus VCL to be precise. Compiler should be smart enough to only compile with those classes and functions that are actually used. I'm quite happy with 1Mb executable size with larger graphical projects, and that's before UPX pack.

    As for the problem i don't know what key events are used for it. You might have some chance with checking if Shift key is held. Checking for Caps lock needs some crossplatform function which maybe Freepascal has. WinAPI maybe but that's Windows-only.

    Edit: By shift i mean, 'A' is code 65 and 'a' is 97. Basically if shift is held, then reduce 32 from ascii value. This will not work with any other characters than A..Z.
    Last edited by User137; 14-03-2011 at 11:43 AM.

  6. #6
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Chesso: Yes, this is cross platform so windowze API is no go, especially since I don't use windowze...
    User137: Yes, I am looking at doing a -32 on a-z keys automatically, but does it also work with caps, backspace and num lock?

    I've had no luck at all getting it to work. So I guess there is no sdl function to do this? Or does anyone have an engine that has that functionality integrated (open source please)? I don't use lazarus so my plain fpc install wont have the VCL. My executable size is already knocking on 800k due to all the libs I'm using.

    cheers,
    code_glitch.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

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
  •