crazyfuturamanoob
May 5th, 2009, 05:10 PM
I absolutely have to do this, and my function doesn't seem to work. I know very little about binary, X11 and keyboard scancodes.
int get_key_state( Display *dpy, char key )
{
char keys[32];
XQueryKeymap( dpy, keys );
int byte = floor( key / 4 );
int bit = key - ( byte * 4 );
switch( bit )
{
case 0:
return keys[byte] & 0x01;
case 1:
return keys[byte] & 0x02;
case 2:
return keys[byte] & 0x04;
case 3:
return keys[byte] & 0x08;
default:
break;
}
printf( "Error! Byte: %d Bit: %d\n", byte, bit );
return 0;
}
I couldn't find much info about X11. And I'm not sure about endianness. Should the switch be inverted?
This is for a console program which is supposed to work only if scroll lock is on.
int get_key_state( Display *dpy, char key )
{
char keys[32];
XQueryKeymap( dpy, keys );
int byte = floor( key / 4 );
int bit = key - ( byte * 4 );
switch( bit )
{
case 0:
return keys[byte] & 0x01;
case 1:
return keys[byte] & 0x02;
case 2:
return keys[byte] & 0x04;
case 3:
return keys[byte] & 0x08;
default:
break;
}
printf( "Error! Byte: %d Bit: %d\n", byte, bit );
return 0;
}
I couldn't find much info about X11. And I'm not sure about endianness. Should the switch be inverted?
This is for a console program which is supposed to work only if scroll lock is on.