Results 1 to 5 of 5

Thread: Keyboard unit: kbReleased problem.

  1. #1

    Keyboard unit: kbReleased problem.

    I've asked this question at the FreePascal site, but haven't received a reply for over a week, so I'm trying here as well:

    I want to use the Keyboard unit that comes with FreePascal to keep track of which keys are currently pressed. In my code I have an array of all keys. I can set a key as pressed by using PollEvent to get keypress events, but I'm unable to get an event when the key is released. It is my understanding that the kbReleased flag should indicate a key release event, but I'm never getting this flag. Here's an excerpt from my test code:

    [pascal]
    Repeat
    K:=GetKeyEvent;
    K:=TranslateKeyEvent(K);
    Write('Got key event with ');
    Case GetKeyEventFlags(K) of
    kbReleased : Writeln('Released key event');
    end;
    Writeln('Got key : ',KeyEventToString(K));
    Until (GetKeyEventChar(K)='q');
    [/pascal]

    It reads keypresses as it should, but I never get the 'Released key event' message.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  2. #2

    Keyboard unit: kbReleased problem.

    I think you should check for release event like this:
    [pascal]
    flags := GetKeyEventFlags(K);
    if (flags and kbReleased) <> 0 then
    writeln('Released key event'):
    [/pascal]

    I suspect that since flags is a byte it can hold many flags joined together by binary or.

  3. #3

    Keyboard unit: kbReleased problem.

    That didn't work. I've even tried using the example that comes with FreePascal, but that didn't work either:

    [pascal]program example1;

    { This program demonstrates the GetKeyEvent function }

    uses keyboard;

    Var
    K : TKeyEvent;

    begin
    InitKeyBoard;
    Writeln('Press keys, press "q" to end.');
    Repeat
    K:=GetKeyEvent;
    K:=TranslateKeyEvent(K);
    Write('Got key event with ');
    Case GetKeyEventFlags(K) of
    kbASCII : Writeln('ASCII key');
    kbUniCode : Writeln('Unicode key');
    kbFnKey : Writeln('Function key');
    kbPhys : Writeln('Physical key');
    kbReleased : Writeln('Released key event');
    end;
    K:=TranslateKeyEvent(K);
    Writeln('Got key : ',KeyEventToString(K));
    Until (GetKeyEventChar(K)='q');
    DoneKeyBoard;
    end.
    [/pascal]

    Can anybody get the above code to report 'Released key event'?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  4. #4

    Keyboard unit: kbReleased problem.

    Months ago I did a lot of testing to retrieve the Release flag, and seems it's not working at all. After asking for it the FPC mailing list, I finally gave up, and moved to platform specific functions. :?

  5. #5

    Keyboard unit: kbReleased problem.

    Well, that's pretty disappointing. They should put that information somewhere on the FreePascal site to keep people from wasting a lot of time getting it to work...
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

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
  •