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

Keycodes file problem?

Post by emendelson »

There seems to be a problem with the latest keycodes file and the current MacOS build of SheepShaver. Testing in Big Sur, in the Preferences, if I check "Use raw keycodes" and specify the latest keycodes file, then the tilde/backquote (~/`) key on the US keyboard produces the section sign and plus/minus sign. This is the same problem that occurred in many earlier versions.

If I do NOT check "Use raw keycodes," then the tilde/backquote key works correctly. Is there any hope of having a corrected keycodes file? I know this a continuing annoyance, and I'll be grateful for any help.
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 issue is related to a difference between ANSI (mostly US) and ISO (most European and several other countries) keyboards. On a QWERTY keyboard, ISO keyboards have an extra (`/~) key between left-shift and Z keys that does not exist on an ANSI keyboard, while ISO keyboards have a (§/±) key where the (`/~) key is on an ANSI keyboard.

I thought it was again solved in the new SDL2-specific keycodes files. I will have another look. May take some time. Possibly it cannot be solved for both ANSI and ISO keyboards. (US-English keyboards do not need the keycodes file.)

I suppose your keyboard is a US ANSI keyboard with the (`/~) key next to the "1" key?

(All my Apple/Mac keyboards are Dutch ISO keyboards. The Dutch keyboard layout is identical to the US keyboard layout with the extra (`/~) key and the (§/±) key next to the "1" key being the only difference.)
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Yes, I have US keyboards. But I distribute apps outside the US so it would be good to have a solution that works everywhere. If this is impossible I could probably make my AppleScript wrappers test for the US locale and write the prefs differently for US and other locations.
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 will again have a look. Note that the keycodes files are not needed with US-English keyboards.

I added the SDL2 scancodes to Mac keycodes translations to the keycodes files to make the SDL2 builds at all useable with non US keyboards. kanjitalk755 was not interested in sorting out the codes. To give you an idea, see: https://www.libsdl.org/tmp/SDL/include/SDL_scancode.h
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 »

Does the problem exist only in the macOS or also the Windows builds?
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 checked and double-checked. The keycodes file is correct for macOS and has a faulty translation for Windows that could seem to solve the issue, but instead breaks the key for all other than US-English layouts.

It is about the SDL2 scancode 53, that needs to be translated to Mac keycode 10.

I am not sure what the issue could be when the keycodes file is used with an US-English keyboard. Could Apple keyboards have been different in the past? Or does an International MacOS9 installation assume an international keyboard?

Do you use an Apple keyboard?

Try and see wat the Key Caps application shows for that key, regardless whether the keycodes file is used or not. Doesn't it show a (§/±) key?

I cannot change it as it will break the key for all other than US-English layouts. In fact, I wonder if I shouldn't change it for the Windows builds.

Better not use the keycodes file with a US-English keyboard.
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 »

Apparently, the international English MacOS expects an ISO keyboard with a (§/±) key at the top-left. That does not change when an US-English keyboard layout is chosen in MacOS.

See this page about ISO and ANSI and languages: https://support.apple.com/en-us/HT201794

With an US-English ANSI keyboard one should not use the keycodes file.
With an ISO keyboard one needs to use the keycodes file, also if it uses an US-English layout.

ISO and ANSI keyboards differ by the shape of the Return key. ISO keyboards also have an extra key, on US-English layout between the left shift key and the Z key, that ANSI keyboards do not have.

As far as I am aware, actual US-English ISO keyboards are rare.

So, the general advice would be to not use the keycodes file with an US-English keyboard.
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 »

But on a Windows host the situation is more complex. There one may need the keycodes file to remap the modifier keys as the Windows logo key cannot be used. There a compromise may be needed. But it would disable the top-left key on ISO keyboards. Loosing the § or ± is not much of a problem, but in French AZERTY layout that top-left key produces @.

I have to think about a solution.
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 installed a USA MacOS9 and expected Key Caps to show an ANSI keyboard because that is the usual keyboard in the USA, but Key Caps shows again an ISO keyboard.
Would the Mac OS in SheepShaver be able to identify my ISO keyboard? Seems very unlikely. Maybe the keyboard in SheepShaver and BasiliskII is always an ISO keyboard.

Which keyboard does MacOS Key Caps show when an ANSI keyboard is used? If it is still an ISO keyboard, that would explain the problem with the top-left key with ANSI keyboards when the keycodes file is used.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

I'm using a MacBook Air with a standard US keyboard. My SheepShaver setups are all US setups. In SheepShaver, OS 9 KeyCaps shows the section/plus-minus at the upper left, next to the "1" key, which is wrong. It shows the tilde/backquote key in the bottom row, to the left of the "Z" key - and of course, on a US keyboard, there is no key in that position. The tilde/backquote is in fact to the left of the "1" in the top row. So, yes, you seem to be correct: SheepShaver always shows an ISO keyboard - or at least, that seems to be the explanation.

Of course, the host macOS Keyboard Viewer shows the correct key layout.

I haven't had a chance to test under Windows yet.

EDIT: Meanwhile, to work around this issue, my AppleScript-based apps (MacOS9, SheepShaver Wrapper) now test for the US or Canada locale, and set keycodes to true or false depending on whether it's one of those two locales or anywhere else in the world.
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 »

emendelson wrote: Wed Aug 18, 2021 11:26 amIn SheepShaver, OS 9 KeyCaps shows the section/plus-minus at the upper left, next to the "1" key, which is wrong.
Well, that is not "wrong", it is the ISO layout that differs from your ANSI layout. Key Caps shows the exact layout on my ISO keyboard, also when using the US-English layout.

SheepShaver (and BasiliskII) apparently use an ISO keyboard layout regardless the attached hardware keyboard or the system language or the language chosen for the keyboard. For people using an actual ISO keyboard everything will work as expected with the keycodes file, in any language layout, while the top-left key will break without the keycodes file.

This is because of the solution that is build into the emulator that works for US-English on ANSI keyboards when the keycodes file is not used. But it does not work properly with several other than US-English languages, even on an ANSI keyboard.

A solution for ANSI keyboards that has been tried before in the keycodes file was to map the top-left key to the extra "international" key next to the Z key on ISO keyboards. That works for ANSI US-English layouts, but it breaks that key with ISO keyboards and even for several languages other than English on ANSI keyboards.

ANSI keyboards are the standard in the USA and in some Asian countries. ISO keyboards are the standard in most of Europe and in many other countries that use 'Roman' languages with multiple diacritics. But in some countries where you would expect ISO keyboards, again ANSI keyboards are used.

There is no single solution for all situations, but the best I can think of so far is to do the translations properly in the keycodes file without a trick to accommodate users of US-English ANSI keyboards and to advise US-English users (who will mostly use ANSI keyboards) to not use the keycodes file.

Now there are also the issues with Windows keyboards...
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 »

emendelson wrote: Wed Aug 18, 2021 11:26 amI haven't had a chance to test under Windows yet.
The current keycodes file uses the "trick" mentioned above for Windows hosts.

Meanwhile, to work around this issue, my AppleScript-based apps (MacOS9, SheepShaver Wrapper) now test for the US or Canada locale, and set keycodes to true or false depending on whether it's one of those two locales or anywhere else in the world.
I am not sure whether ANSI or ISO keyboards are used in Canada.
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 »

Canada uses two types of keyboards, an English ANSI keyboard or a bi-lingual ISO keyboard.
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: Wed Aug 18, 2021 1:32 pm Canada uses two types of keyboards, an English ANSI keyboard or a bi-lingual ISO keyboard.
I've set up my systems to check for the en_CA locale; if anyone reports keyboard problems, I'll try to find a fix.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Keycodes file problem?

Post by adespoton »

emendelson wrote: Wed Aug 18, 2021 2:26 pm
Ronald P. Regensburg wrote: Wed Aug 18, 2021 1:32 pm Canada uses two types of keyboards, an English ANSI keyboard or a bi-lingual ISO keyboard.
I've set up my systems to check for the en_CA locale; if anyone reports keyboard problems, I'll try to find a fix.
Anyone in English speaking Canada will use the US ANSI keyboard. It's only people buying a French localized computer that will have the bi-lingual ISO keyboard, or possibly government purchases as well.
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 have found the solution.

In the old BasiliskII ReadMe https://basilisk.cebix.net/README
I found this:

keyboardtype <keyboard-id>

Specifies the keyboard type that BasiliskII should report to the MacOS.
The default is "5" which is a "Apple Extended Keyboard II (ISO)",
but many other numbers are understood by most versions of the MacOS
(e.g. 11 is a "Macintosh Plus Keyboard with keypad", 13 is a "Apple PowerBook Keyboard (ISO)" )


It still works.

Code: Select all

keyboardtype 2
makes SheepShaver and BasiliskII use an ANSI Apple Extended Keyboard

The setting should be set according to the actual keyboard that is used on the host.

2 = ANSI
5 = ISO (default)

I do not know if there is a way to automatically detect the keyboard used on the host.

(Note that the currently used keycodes file will not work correctly on Windows because it was edited with the "trick" for ANSI keyboards.)
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 will post compatible new keycodes files later today.
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 »

New keycodes files here: http://ronaldpr.home.xs4all.nl/keycodes ... 8-2021.zip

See also ReadMe in the download.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Well done, Ronald! Thank you!

Here is a page on detecting the current keyboard layout. Perhaps kanjitalk755 might consider building this into the code?

https://stackoverflow.com/questions/215 ... l-a-script
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: Keycodes file problem?

Post by emendelson »

Wait - this solution does not work correctly with a US keyboard. The KeyCaps program shows the correct ANSI layout, with the tilde/backquote key at the upper left. But when I type that key, it produces the section mark. Does the keyboard file need to be changed again?

EDIT: (I was able to get the tilde key to type the tilde, by changing 53 10 to 53 50 in the sdl cocoa section of the file, but, if I understand you correctly, this breaks other keyboard layouts.)

Here is my .SheepShaver_prefs file (and the keycodes file in the SheepShaver folder is the one that you uploaded a few minutes ago):

Code: Select all

disk SheepShaver.4gb.sparsebundle
extfs /Users/edward/Documents
screen win/1024/768
windowmodes 0
screenmodes 0
seriala 
serialb 
rom 
bootdrive 0
bootdriver 0
ramsize 268435456
frameskip 1
gfxaccel true
nocdrom true
nonet false
nosound false
nogui true
noclipconversion false
ignoresegv true
ignoreillegal true
jit true
jit68k false
keyboardtype 2
hardcursor false
hotkey 0
scale_nearest false
scale_integer false
cpuclock 0
yearofs 0
dayofs 0
mag_rate 0
swap_opt_cmd false
sound_buffer 0
name_encoding 0
ether slirp
keycodes true
keycodefile keycodes
mousewheelmode 1
mousewheellines 3
dsp /dev/dsp
mixer /dev/mixer
idlewait false
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 »

As far as I can see, this is about the language keyboard layouts, not about the ANSI or ISO keyboard type. Different language keyboard layouts can be applied to both ANSI and ISO.

In macOS the language keyboard layout is set in System Preferences > Keyboard > Input Sources. Changing the language changes the language layout and not the keyboard type.

About setting keyboard type, see: https://support.apple.com/guide/mac-hel ... lp2886/mac
("Change Keyboard Type" does not appear in my Keyboard preferences.)
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 have no time to look into this further now. Changing 53 -> 10 to 53 -> 50 may seem to correct this, but it is not right. It is the old "trick" that directs the top-left key press to the on ANSI non-existing extra ISO key.

Edit: You did not add the needed line in the prefs file, so your SheepShaver keyboard should be still ISO.
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 1:26 pm I have no time to look into this further now. Changing 53 -> 10 to 53 -> 50 may seem to correct this, but it is not right. It is the old "trick" that directs the top-left key press to the on ANSI non-existing extra ISO key.

Edit: You did not add the needed line in the prefs file, so your SheepShaver keyboard should be still ISO.
Isn't the correct line

keyboardtype 2

?? That line is in the file I posted in the earlier post. It is around line 25 (more or less).
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. You are right. It does not work as intended. I have to go now. I will look into this later.
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 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.
Post Reply