Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard input problem for games #23

Open
tanoxyz opened this issue Jan 8, 2023 · 1 comment
Open

Keyboard input problem for games #23

tanoxyz opened this issue Jan 8, 2023 · 1 comment

Comments

@tanoxyz
Copy link

tanoxyz commented Jan 8, 2023

Hi!
I was trying to use the CPC emulator to bundle a web version of a game I made, but I've noticed that there is a problem with the input handling. Maybe you already know about this problem and that there is no clear solution .

The problem

In

case SAPP_EVENTTYPE_CHAR:
you check most keys in the keyboard from char events, as they don't specify key down/up, the key up and down event are sent in the same frame. This seems mostly fine on the default CPC's firmware but some games may need to hold the key for more than 1 frame, for example our game's jump height varies based on how long you have been pressing the key. Our game
I suppose that you did it that way in order to map any keyboard layout to the original, for example on the CPC's case the symbol " is on the Key 2 but on today's keyboards it may vary.

Solutions?

For our game, I've ignored the char events from A to Z and used the usual key down/up events to detect them, code here. But a more robust solution would be to just map the all key up/down events to the original keyboard's position. Although some keys won't match in some keyboards, it will be the "real position", in Retro Virtual Machine works that way.
We can also add a toggle to change the layout to "physically correct" or not.

Thanks for these emulators by the way!

@floooh
Copy link
Owner

floooh commented Jan 10, 2023

Thanks for the input, I need to think about this a bit :)

In general, I was hoping that most games would be able to use the joystick emulation (when this is activated, some host keys are intepreted as joystick input instead of keyboard input, but this also has issues - namely that the arrow keys and Spacebar no longer work as regular keys).

The reason that CHAR input is used is indeed that this provides an automatic key mapping for international (host) keyboards, instead of trying to map the home computer keyboards to modern 'physical' keyboards.

Another thing I have somewhere down on the todo list is virtual onscreen keyboards and joysticks, this would mainly be useful for mobile devices, but would also help to make 'exotic keys' on some home computers accessible which are currently ignored. This would not help with your specific problem though :)

I guess the best solution is - as you mentioned - a separate input mode which would use key up/down events instead of CHAR for all keyboard input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants