sechshelme / Lazarus-SDL3.0-Packages_and_Examples

2 stars 0 forks source link

Escape key not detected (Linux) #1

Closed rchastain closed 5 months ago

rchastain commented 5 months ago

Hello!

Thank you for sharing your work. I didn't even know that there was a SDL3. :)

I tested successfully all your examples. But the detection of the Escape key doesn't work here (Linux). Does it work for you?

Regards.

Roland

rchastain commented 5 months ago

By the way, in the thread example, I had to add this:

uses
{$IFDEF linux}
  cthreads,
{$ENDIF}
sechshelme commented 5 months ago

Hallo!

Vielen Dank, dass Sie Ihre Arbeit geteilt haben. Ich wusste nicht einmal, dass es ein SDL3 gibt. :) :)

Ich habe alle Ihre Beispiele erfolgreich getestet. Allerdings funktioniert die Erkennung der Escape-Taste hier nicht (Linux). Funktioniert es bei Ihnen?

Grüße.

Roland

Does ESC not work in all examples? Everyone goes with me. Use Linux Mint 64bit.

sechshelme commented 5 months ago

Im Thread-Beispiel musste ich übrigens Folgendes hinzufügen:

uses
{$IFDEF linux}
  cthreads,
{$ENDIF}

I can do without it.

rchastain commented 5 months ago

Does ESC not work in all examples?

No, it doesn't work in any example here.

I can do without it.

Really? I am surprised that it works for you without that.

My OS is Linux Mageia. When I have time, I will try on another computer.

Viele Grüße.

Roland

sechshelme commented 5 months ago

Funktioniert ESC nicht in allen Beispielen?

Nein, das funktioniert hier in keinem Beispiel.

Are you sure the SDL window was active? If it's the console window, of course it doesn't work.

Otherwise, add the following and see if something comes in when you press the key.

      while SDL_PollEvent(@e) <> 0 do begin
        WriteLn('event: ', e.type_); // neu
        case e.type_ of
          SDL_EVENT_KEY_DOWN: begin
            WriteLn('key: ', e.key.keysym.sym); // neu
            case e.key.keysym.sym of
rchastain commented 5 months ago

Thanks. With your code, I could find the problem. When I press Escape, I get key: 41.

But with WriteLn('SDLK_ESCAPE = ', SDLK_ESCAPE); I get SDLK_ESCAPE = 27.

sechshelme commented 5 months ago

You're right, there's something wrong with ESC, on my laptop it comes in 41 instead of 27. Even if I test it in a C program. I'll have to take a closer look tomorrow to see whether I'm querying ESC incorrectly or whether it's a bug in SDL3.

Are you using a PC or laptop?

rchastain commented 5 months ago

A laptop.

rchastain commented 5 months ago

"The key code for the escape key is 27 but the scanscode is 41." Source.

Gute Nacht!

sechshelme commented 5 months ago

Now I don't understand anything anymore. The Pascal example comes with “41” and the C version comes with “27”. And all this in exactly the same PC session.

With SDL2 there is also a 27 for FPC

Do you have any idea what that could be?

      while SDL_PollEvent(@event) <> 0 do begin
        SDL_Log('event: %i', event.type_); // neu
        case event.type_ of
          SDL_EVENT_KEY_DOWN: begin
            SDL_Log('key: %i', event.key.keysym.sym); // -> 41
            case event.key.keysym.sym of
              SDLK_ESCAPE: begin
                quit := True;
              end;
            end;
          end;
          SDL_EVENT_QUIT: begin
            quit := True;
          end;
        end;
      end;   
    while (!loopShouldStop)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            SDL_Log("event: %i", event.type); // neu
            switch (event.type)
            {
                case SDL_EVENT_KEY_DOWN:
                    SDL_Log("Key: %i", event.key.keysym.sym);
                    switch (event.key.keysym.sym)
                    {
                       case SDLK_ESCAPE:
                       loopShouldStop = SDL_TRUE;
                       break;
                    }
                    break;
                case SDL_EVENT_QUIT:
                    loopShouldStop = SDL_TRUE;
                    break;
            }
        }
    }
rchastain commented 5 months ago

No, I have no idea. Maybe you could ask the question on Lazarus forum?

sechshelme commented 5 months ago

Found a mistake.

They patched in a line at SDL_KeyboardEvent. Therefore I got something other than keysym back.

typedef struct SDL_KeyboardEvent
{
    SDL_EventType type; /**< ::SDL_EVENT_KEY_DOWN or ::SDL_EVENT_KEY_UP */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_WindowID windowID; /**< The window with keyboard focus, if any */
    SDL_KeyboardID which;  /**< The keyboard instance id, or 0 if unknown or virtual */
    Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
    Uint8 repeat;       /**< Non-zero if this is a key repeat */
    Uint8 padding2;
    Uint8 padding3;
    SDL_Keysym keysym;  /**< The key that was pressed or released */
} SDL_KeyboardEvent;
  TSDL_KeyboardEvent = record
    _type: uint32;
    reserved: uint32;
    timestamp: uint64;
    windowID: TSDL_WindowID;
    which: TSDL_KeyboardID;  // neu
    state: uint8;
    _repeat: uint8;
    padding2: uint8;
    padding3: uint8;
    keysym: TSDL_Keysym;
  end;  
rchastain commented 5 months ago

Congratulations. It works now. I close the issue. Bis bald!

sechshelme commented 5 months ago

I would get the latest version from sdl. There were even more errors when it came to the keyboard.

sechshelme commented 5 months ago

By the way, in the thread example, I had to add this:

uses
{$IFDEF linux}
  cthreads,
{$ENDIF}

Could you create a new issue for this so I can take a closer look?