PDA

View Full Version : Scandinavian Keyboard Layouts


chris
November 11, 2010, 23:38
Well, I'm trying to debug a problem with regard to alternative keyboard layouts and Hengband. I'm not sure if this has been fixed in Angband or not.

Take a look at: http://freepages.genealogy.rootsweb.ancestry.com/~tonyhansen/Scandinavian_and_Germanic_Letters/index.html

Especially the pictures at the bottom. To press the '@' key on the Icelandic layout, for example, one presses the right alt key and the Q key simultaneously.

Windows generates the following messages in a normal app:
WM_KEYDOWN : 0-17 1900545 //17 is 0x11 CONTROL
WM_KEYDOWN : 0-18 557318145 //18 is 0x12 ALT
WM_KEYDOWN : 0-81 537919489 //81 is 0x51 Q
WM_CHAR : 0-64 537919489 //Bingo ... 64 is ASCII speak for '@'

The problem is in Main-Win.c, we take that last WM_KEYDOWN for the Q key and pass it off to process_keydown() which says, yup, I got it. So we return 0 back to Windows for the WM_KEYDOWN, and Windows says OK, guess you don't need that WM_CHAR after all.

I'm just starting to debug this, and am in over my head. I'm wondering if this rings any bells with anybody. I need to get Angband (well, Hengband) to not think it likes that Ctl+Alt+Q on the WM_KEYDOWN so that Windows will oblige me with a WM_CHAR for the '@' key, which is correct for this keyboard layout.

Any thoughts?

Thanks in advance,
--Chris

chris
November 12, 2010, 00:07
Vanilla code looks fine. Hengband has extra code, probably to support Japanese Keyboard layouts. Essentially, any time the Alt key is pressed, they send keys to the Angband Terminal. So while Vanilla has:

case WM_KEYDOWN:
{
bool mc = FALSE;
bool ms = FALSE;
bool ma = FALSE;

/* Extract the modifiers */
if (GetKeyState(VK_CONTROL) & 0x8000) mc = TRUE;
if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;

/* Handle "special" keys */
if (special_key[(byte)(wParam)])
{
/* blah */
}
}

Hengband had extra code like:

if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )

where ignore_key is hardcoded to just a handful of keys to ignore for the Alt. 'Q' and '2' are definitely not in that list, and hardcoding is a bad idea anyway.

I just added some conditional compilation and now my Icelandic layout seems to work just fine.

Sorry for the premature bother. I did the whole "Hey, I'm stuck! Let me post on a forum hoping for a quick answer!" thing rather than just grunting it out. :rolleyes:

Derakon
November 12, 2010, 00:57
No worries, now if someone else runs into this problem they can search and find your post with a solution. :) It's not like we're short on space for posts.

chris
November 12, 2010, 02:06
Good Point. Here's a patch that should work on Hengband. To be truly useful, I should at least give that :)

diff -r 4db84295fa31 src/main-win.c
--- a/src/main-win.c Thu Nov 11 14:05:23 2010 -0700
+++ b/src/main-win.c Thu Nov 11 19:02:51 2010 -0700
@@ -4248,10 +4248,14 @@
if (GetKeyState(VK_SHIFT) & 0x8000) ms = TRUE;
if (GetKeyState(VK_MENU) & 0x8000) ma = TRUE;

+ /* Handle "special" keys */
+#if defined JP
Term_no_press = (ma) ? TRUE : FALSE;
-
- /* Handle "special" keys */
if (special_key[(byte)(wParam)] || (ma && !ignore_key[(byte)(wParam)]) )
+#else
+ Term_no_press = FALSE;
+ if (special_key[(byte)(wParam)])
+#endif
{
bool ext_key = (lParam & 0x1000000L) ? TRUE : FALSE;
bool numpad = FALSE;