Oj vad knöligt...
Finns det verkligen inget sätt att läsa av tangenterna utan någon "hjälpsam" funktion som knökar ihop det och sedan måste knökas tillbaka till scancodes och shiftstate?
Här är koden som skall ta emot keycode och shiftstate samt en av tabellerna som hör till.
Kod: Markera allt
int KeyConv(int Key, int State, int* twokey){
int result;
bool capsLock;
//printf("Keycode %02x\n", Key);
//static int twokey = 0;
//printf("deb KeyConv keycode: %02x\n", Key);
result = -1; //assume not valid keypress
capsLock = ((State & 0x02) !=0); //keep capslock status
State &= ~0x12; //clear capslock and numlock bits
if (*twokey == 0){ //2:nd of twokey?
switch (State){ //no, convert to char, shift/crrl/alt/caps selects conv.table
case 0x00: if (Key<0x80){
if (!capsLock)
result = KeyNone[Key];
else
result = KeyLock[Key];
break;
};
case 0x01: if (Key<0x80) result = KeyShift[Key]; break;
case 0x04: if (Key<0x80) result = KeyCtrl[Key]; break;
case 0x08: if (Key<0x80) result = KeyAlt[Key]; break;
case 0x40: if (Key<0x80) result = KeyWin[Key]; break;
case 0x80: if (Key<0x80) result = KeyAltGr[Key]; break;
};
}
else{
switch (*twokey){
case -0x100: if (Key<0x80) result = Key2Q[Key]; break;
case -0x200: if (Key<0x80) result = Key2K[Key]; break;
case -0x300: if (Key<0x80) result = Key2O[Key]; break;
case -0x400: if (Key<0x80) result = Key2AltK[Key]; break;
};
*twokey = 0;
};
if ((result<0) && (result!=-1) ){
*twokey = result;
result = -1;
};
return result;
}; //KeyConv
short KeyNone[0x80] = {
// esc 1 2 3 4 5 6
// 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
-1, -1, -1, -1, -1, -1, -1, -1, -1, 27, '1', '2', '3', '4', '5', '6',
// 7 8 9 0 + ' l bs backsp tab q w e r t y u i
// 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
'7', '8', '9', '0', '+', -1, p+29, p+42, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
// o p å ^ return ? a s d f g h j k l ö
// 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
'o', 'p', 229, -1, p+34, -1, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 246,
// ä § ? * z x c v b n m , . - ? num *
// 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
228, -1, -1, '\'', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', -1, '*',
// ? space ? F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 ? ? num 7
// 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
-1, 0x20, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, '7',
// num 8 num 9 num - num 4 num 5 num 6 num + num 1 nom 2 num 3 num 0 num . ? ? < F11
// 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
'8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', -1, -1, 0x3c, -1,
// F12 ? ? ? ? ? ? ? ? ? num / ? ? ? home uparrow
// 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, p+12,
// pgup leftarr rghtarr end downarr pgdown insert delete ? ? ? ? ? ? ? ?
// 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
p+15, p+2, p+3, -1, p+13, p+14, -1, p+31, -1, -1, -1, -1, -1, -1, -1, -1
};//KeyNone