Macbooks, numeric keypads, and Avernum

AuthorTopic: Macbooks, numeric keypads, and Avernum
Warrior
Member # 7633
Profile #0
First, the bad news: New Macbooks don't have the "emulated numeric keypad" feature where you get a keypad by typing {jkluio789}. This makes the Avernum games a lot more annoying to play, as you can't move effectively. (The arrow keys move you in kind of weird directions, and don't work at all for the diagonals.)

The good news: There's a simple solution. Right now, it's impractical for anyone except developers. (To those who are: DYLD_INSERT_LIBRARIES.) However, Jeff could integrate it into the games pretty easily - consider this a black-box code contribution. :)

Here it is. Note that this should be configured to only apply to x86 systems - it's not useful on PPC, as Powerbooks have numeric keypad built-in.
#define FN_KEY 0x8000000000000000LL

struct { int from, to; } keypad_conv[9] = {
{26, 89}, {28, 91}, {25, 92},
{32, 86}, {34, 87}, {31, 88},
{38, 83}, {40, 84}, {37, 85}
};

void GetKeysWrapper(uint64_t *buf) {
int i;
GetKeys(buf);
if(buf[1]) return;
for(i = 0; i < 9; i++) {
if(buf[0] == (FN_KEY | (1LL << keypad_conv[i].from))) {
buf[0] = 1LL << keypad_conv[i].to;
buf[1] = 1LL << (keypad_conv[i].to - 64);
return;
}
}
}

Posts: 66 | Registered: Saturday, November 4 2006 08:00
Infiltrator
Member # 5576
Profile Homepage #1
Out of curiosity, what exactly does the proposed code block do? At a glance it's clear that it's mapping some set of nine inputs to nine others, but from what to what is it mapping? Basically, what would the difference to the user be when using the keyboard? (Save us all having to look up the virtual key codes please. :P )

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
Agent
Member # 8030
Profile Homepage #2
Have you e-mailed Jeff by any chance?

Many laptops I've seen have numeric keyboards that work only if number lock is on. However, I highly doubt you wouldn't have noticed that already.

--------------------
I dub thee...
Posts: 1384 | Registered: Tuesday, February 6 2007 08:00
Warrior
Member # 7633
Profile #3
Excalibur, Apple decided to drop NumLock and the numeric keypad from the most recent revision of MacBooks. I'm not quite sure why, but my code restores it within Avernum.

Good point about mailing Jeff, BTW. I'll go ahead and do that.

Niemand, the specific mapping this implements is:
Fn+j -> keypad 1Fn+k -> keypad 2Fn+l -> keypad 3Fn+u -> keypad 4Fn+i -> keypad 5Fn+o -> keypad 6Fn+7 -> keypad 7Fn+8 -> keypad 8Fn+9 -> keypad 9
Posts: 66 | Registered: Saturday, November 4 2006 08:00
Infiltrator
Member # 5576
Profile Homepage #4
Nice; looks really useful, Duskwolf.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00