pygame key code issue

Issue #1074 new
bsod123456 created an issue

I have a crashed problem with the MASTER branch when start the cardwirth.py .

The error trace is the same as this issue:

https://bitbucket.org/k4nagatsuki/cardwirthpy-reboot/issues/1003/kb#comment-59675276

Then I found that, in my enviroment (Windows 7), the pygame’s(or SDL2) key code is too big than normal:

>>> hex(pygame.K_LCTRL)
'0x400000e0'

>>> hex(pygame.key.key_code('left ctrl'))
'0x400000e0'

This key code is come from:

https://github.com/pygame/pygame/blob/main/src_c/key.c#L741

Returned by SDL_GetKeyFromName.

I don’t know why the key code is so big, but I work around the problem in cw/eventrelay.py class KeyEventRelay .

I make a new method of the class KeyEventRelay :

def local_keycode(self, sdl_keycode: int):
    return 0xffff & sdl_keycode

And then, call it in every other methods like this:

def keydown(self, keycode: int) -> None:
    keycode = self.local_keycode(keycode)
    key = self.keymap.get(keycode, None)

        ...

After all of that, I finally succeeded in running the game。

Comments (2)

  1. k4nagatsuki repo owner

    What version of pygame do you have? If it is a pygame 2 series, that may be the cause of your problem.

    CardWirthPy does not yet support pygame 2. The current version of pygame 2 is difficult to work with wxPython. The following issues need to be resolved:

    https://github.com/pygame/pygame/issues/1574

    Therefore, CardWirthPy still uses pygame 1.9.6.

    If it is Windows-only, it is not impossible to support pygame 2, but in that case wx.Window#AssociateHandle, and since this method only supports Windows, it would probably truncate other platforms. I have not been able to make that decision.

  2. bsod123456 reporter

    Yes, I use the latest version of pygame.

    And, I also found that window embedded issue can’t be solved at present.

    I’ll rollback the pygame version.

  3. Log in to comment