Keycodes file problem?

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Ronald P. Regensburg wrote: Thu Aug 19, 2021 7:31 pm I think I found it.

Key Caps can be useful for visual support for which keys to use on which keyboard layout. The keyboardtype setting in the prefs file is helpful. But the keyboardtype setting does not change the behaviour.

Our assumptions and hence our instructions in the setup manuals were always wrong.
We tell users that the keycodes file is not needed for US-English and the keycodes file is needed for other languages. That worked for many but not all users.

What seems to work for all users and for all languages, and so far I found no exceptions:

If your keyboard is an ANSI keyboard, do not use the keycodes file.
If your keyboard is an ISO keyboard do use the keycodes file.

Our instructions so far did work for many users because most US-English users use a ANSI keyboard and many users of other languages use an ISO keyboard.
That is extremely helpful. Thank you. Question: does the keyboardtype setting in the prefs have any practical effect at all? You wrote that it is helpful - but how?

Also, is it possibly that kanjitalk755 might add a test for the keyboard type in the code?
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

The keyboardtype setting has no effect on the behaviour. It is helpful by making it possible to show in Key Caps your keyboard layout and result of key presses as it is on your real keyboard. The keyboardtype setting is irrelevant if you never use Key Caps for reference.

I do not know if it is at all possible to detect the type of the keyboard used on the host. It will no doubt be different on different hosts. I will ask kanjitalk755.
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

Ronald P. Regensburg wrote: Thu Aug 19, 2021 7:31 pmIf your keyboard is an ANSI keyboard, do not use the keycodes file.
If your keyboard is an ISO keyboard do use the keycodes file.
But if no keycodes file is used, there is no good solution for the issue with the Windows key in Windows on ANSI keyboards.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Ronald P. Regensburg wrote: Thu Aug 19, 2021 8:34 pm I do not know if it is at all possible to detect the type of the keyboard used on the host. It will no doubt be different on different hosts. I will ask kanjitalk755.
This page may help:

https://stackoverflow.com/questions/544 ... een-or-usb
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

That would be for macOS. How about Windows and Linux?

And there is still the issue with the Windows key.
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

I studied the behaviour of SS/BII with and without the keycodes file and I found that most of the keycodes file is not needed with any keyboard type or language layout. All SDL2 scancodes to Mac keycodes are done in SS/BII. Only the top-left key needs a correction for ISO keyboards:

Mac keycodes (characters as in US-English):
top-left key on ISO: 10 (Sectionsign)
top-left key on ANSI: 50 (Grave)

international key on ISO: 50 (Grave)
international key on ANSI: does not exist

SDL2 scancodes (regardless keyboard):
top-left key: 53
international key: 100

SDL2 to Mac translations needed on an ANSI keyboard:
53 -> 50
100 -> does not exist

SDL2 to Mac translations needed on an ISO keyboard:
53 -> 10
100 -> 50

SDL2 translation in SS/BII (without keycodes file and regardless keyboard):
53 -> 50
100 -> 50

For ISO keyboards only this correction is needed in the keycodes file:
53 -> 10
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Does this mean it is possible to reduce the keycodes file to those few items, and let SS/BII supply the other keys automatically?
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

Yes, at least on macOS and Linux hosts.

So far the keycodes files are compatible with all previous BII/SS versions, and I think it is best to keep those parts in the keycodes files. For SDL2 builds on macOS and Linux hosts no keycodes file is needed with ANSI keyboards and with ISO keyboards this should suffice:

Code: Select all

#
# OSX/macOS (SDL2)
# Linux/X11 (SDL2)
#
sdl cocoa
sdl x11
53	10	# top-left key on iso
(On Linux swap_opt_cmd should best be re-enabled with the use of a keycodes file. At the moment swap_opt_cmd is forced to false when a valid keycodes file is used.)

For Windows it is more complex because modifier keys need adjustment, which makes a keycodes file needed with both ANSI and ISO keyboards.

On ANSI keyboards:

Code: Select all

#
# Windows (SDL2)
#
sdl windows
#
224	58	# Ctrl Left (--> Option)
226	55	# Alt Left (--> Command)
230	55	# Alt Right (--> Command)
On ISO keyboards:

Code: Select all

#
# Windows (SDL2)
#
sdl windows
#
53	10	# top-left key on iso
224	58	# Ctrl Left (--> Option)
226	55	# Alt Left (--> Command)
230	55	# Alt Right (--> Command)
(If on Windows swap_opt_cmd would be re-enabled with the use of a keycodes file, the last two lines in both would not be needed.
Edit: Depends on the level at which swap_opt_cmd works. Maybe better not re-enable it on Windows to prevent confusion.)

For all three host systems, macOS, Windows, and Linux, the keycodes for ISO keyboard can be combined in one file. But for Windows and ANSI keyboard a separate keycodes file would be needed.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Thank you. I'll modify my Mac apps to use the shorter keycodes file, but I'll wait until we figure out if it's possible to detect an ANSI or ISO keyboard in a reliable way.

I'll won't do anything with my Windows apps until this gets sorted out a bit more. (Also I haven't tried to build SS/BII on Windows for more than a year.)

Thank you for sorting this out!
User avatar
Ronald P. Regensburg
Expert User
Posts: 7821
Joined: Thu Feb 09, 2006 10:24 pm
Location: Amsterdam, Netherlands

Re: Keycodes file problem?

Post by Ronald P. Regensburg »

For macOS and Linux it makes no difference whether you use the existing keycodes files or the shorter ones. The relevant translations are the same. Only superfluous translations are removed from the shorter ones. With ANSI keyboards no keycodes file is needed, the file is only needed with ISO keyboards.

For Windows it is more complicated because the Windows keys cannot be used. With "swap_opt_cmd false", there will be no command key in the emulator and with "swap_opt_cmd true" there will be no option key in the emulator. That is why I chose to make the the Alt keys the command keys and the left control key the option key. But then there must also be a keycodes file for ANSI keyboards with Windows.
Post Reply