Strange keyboard input issues with PDCurses/SDL

11 posts / 0 new
Last post
salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Strange keyboard input issues with PDCurses/SDL

I've compiled an AmigaOS 4.x of a game engine I'm working on that uses PDCurses/SDL for the "graphics".

Don't know why but there are strange problems when I try to use the buttons on the numpad like:
1) numlock has to be set to off (instead of on) in order for keys to produce numbers
2) when numlock is off and pressing and releasing a numpad key it gets stuck until I press another key sending the input event over and over
3) not all numpad keys produce correct codes even with numlock off

The main input loop is pretty simple ATM and looks like this:

  1. int input;
  2. while ((input = getch()) != KEY_ESCAPE) {
  3. switch (input) {
  4. case '1': Move(map, cx, cy, -1, 1); break;
  5. case KEY_DOWN:
  6. case '2': Move(map, cx, cy, 0, 1); break;
  7. case '3': Move(map, cx, cy, 1, 1); break;
  8. case KEY_LEFT:
  9. case '4': Move(map, cx, cy, -1, 0); break;
  10. case '5': Move(map, cx, cy, 0, 0); break;
  11. case KEY_RIGHT:
  12. case '6': Move(map, cx, cy, 1, 0); break;
  13. case '7': Move(map, cx, cy, -1, -1); break;
  14. case KEY_UP:
  15. case '8': Move(map, cx, cy, 0, -1); break;
  16. case '9': Move(map, cx, cy, 1, -1); break;
  17. default: fprintf(stderr, "Unknown input: %02x\n", (unsigned int)input); break;
  18. }
  19. RefreshScreen(disp, map, cx, cy);
  20. }

PDCurses version used is latest 3.4 one compiled with:


$ tar -zxf ~/Downloads/PDCurses-3.4.tar.gz
$ cd PDCurses-3.4/sdl1
$ make CC=ppc-amigaos-gcc SFLAGS=-I/SDK/local/common/include/SDL SLIBS=-lSDL DEMOFLAGS=-use-dynld

The AmigaOS 4.x test program I made can be downloaded here:
http://dl.dropbox.com/u/26599983/cursesgame.7z

I also compiled a Linux version using normal curses under Ubuntu and it works fine there (I haven't gotten either X11 or SDL PDCurses to compile under Ubuntu so I wasn't able to check if it was a general PDCurses bug or an AmigaOS/SDL specific one).

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Just tried compiling with

Just tried compiling with Spot's 3.3 version of SDL PDCurses and it has the same issues. Controlling with the arrow keys works fine just not the numpad for some reason...

BTW in curses setup code I have:

  1. if (keypad(m_window, TRUE) != OK) {
  2. throw Exception(ERR_CURSES);
  3. }

to enable using the arrow and numpad keys (if I don't do this they don't work at all).

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
Just tried compiling on

Just tried compiling on Windows with SDL PDCurses and numpad works correctly there so it appears to be a problem with AmigaOS 4.x SDL...

Currently I'm debating whether I should write an intuition backend for my game and ignore PDCurses for AmigaOS:es or write an intuition backend for PDCurses which hopefully will work better than the current SDL one.

Thematic
Thematic's picture
Offline
Last seen: 3 years 3 months ago
Joined: 2011-10-25 02:51
Well, I have tried something

Well, I have tried something with SDL pdcurses before and that one, while compiling without errors (don't remember if there were warnings), crashed.

broadblues
broadblues's picture
Offline
Last seen: 4 years 1 month ago
Joined: 2012-05-02 21:48
SDL has had a number of

SDL has had a number of keyboard bugs over time, so I would guess this one of them.

afxgroup
afxgroup's picture
Offline
Last seen: 10 months 2 weeks ago
Joined: 2011-02-03 15:26
yes. i remember also i've

yes. i remember also i've fixed something in the past that was related to UFO or another game... if someone want to take a look at keyboard handling, this is the file:

http://code.google.com/p/os4sdl/source/browse/trunk/src/video/amigaos4/SDL_os4events.c

there are some issues on SDL i'm aware of.. onr of this is the SDL_Kill that doesn't work (but i think because we have no way to kill a thread like other platforms..)

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
I'm currently looking at

I'm currently looking at keyboard handling in OS4 SDL and it seems that numlock key isn't handled at all (KMOD_NUM is always cleared) except indirectly due to the fact that intuition generates different rawkey codes from IDCMP_RAWKEY depending on whether numlock is enabled or not (also I made the discovery that no IDCMP_RAWKEY messages are sent by intuition when the numlock key is pressed/released).

Also KMOD_CAPS seems to be handled weirdly in that it is set while the caps lock button is being held down and unset otherwise instead of being set when it's enabled and unset when it's disabled (is this really the correct/wanted behavior?).

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
If I disable the "Special

If I disable the "Special handling for CAPSLOCK key" in os4video_HandleKeyboard() then the capslock key works exactly like it does in SDL on Ubuntu so obviously this special handling shouldn't be there because it just causes incorrect behavior.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
After some more testing it

After some more testing it doesn't look there is a way to easily see if numlock is enabled or not in AmigaOS as IEQUALIFIER_NUMERICPAD seems to only say if the button just pressed was on the numpad or not (I guess that's why it's called IEQUALIFIER_NUMERICPAD and not IEQUALIFIER_NUMLOCK).

Probably this strange handling of numlock is because the classic Amiga keyboards did not have a numlock key, but it also makes it hard to have a standards compliant SDL implementation on AmigaOS. I guess easiest way to fix PDCurses would be to just add a hack so that it assumes that numlock is always on, only problem with this is that it might break if SDL keyboard handling is changed in the future to be more correct.

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
First screenshot of a test

First screenshot of a test program running on PDCurses Amiga native backend:

IMAGE(http://dl.dropbox.com/u/26599983/pdcurses-amiga.png)

The font used is good old topaz 8 (will be configurable).

afxgroup
afxgroup's picture
Offline
Last seen: 10 months 2 weeks ago
Joined: 2011-02-03 15:26
do you have a patch for SDL?

do you have a patch for SDL? If yes.. merge it! :)

[Edit]
i've seen you did it already. thx :)

Log in or register to post comments