Home » Developing U++ » U++ Developers corner » GET KEY STATE for Linux and win32
GET KEY STATE for Linux and win32 [message #23240] |
Fri, 02 October 2009 11:49 |
|
Hello All!
I was implemented an interesting method for get key state:
The code like this:
bool get_key_state(dword p_k){
#ifdef PLATFORM_WIN32
//... Here need to optimize
if(p_k & 0xffff)
return (((char)::GetKeyState(p_k & 0xffff)) & 128);
if(p_k & K_ALT)
return GetAlt();
if(p_k & K_SHIFT)
return GetShift();
if(p_k & K_CTRL)
return GetCtrl();
#elif PLATFORM_X11
char key_map_stat[32];
XQueryKeymap(Xdisplay, key_map_stat);
if(p_k & 0xffff){
KeyCode k_code = XKeysymToKeycode(Xdisplay, p_k & 0xffff);
return ((key_map_stat[k_code >> 3] >> (k_code & 7)) & 1);
}
if(p_k & K_ALT){
const KeyCode alt_l = XKeysymToKeycode(Xdisplay,XK_Alt_L);
const KeyCode alt_r = XKeysymToKeycode(Xdisplay,XK_Alt_R);
return (((key_map_stat[alt_l >> 3] >> (alt_l & 7)) & 1)
||((key_map_stat[alt_r >> 3] >> (alt_r & 7)) & 1));
}
if(p_k & K_SHIFT){
const KeyCode shift_l = XKeysymToKeycode(Xdisplay,XK_Shift_L);
const KeyCode shift_r = XKeysymToKeycode(Xdisplay,XK_Shift_R);
return (((key_map_stat[shift_l >> 3] >> (shift_l & 7)) & 1)
||((key_map_stat[shift_r >> 3] >> (shift_r & 7)) & 1));
}
if(p_k & K_CTRL){
const KeyCode control_l = XKeysymToKeycode(Xdisplay,XK_Control_L);
const KeyCode control_r = XKeysymToKeycode(Xdisplay,XK_Control_R);
return (((key_map_stat[control_l >> 3] >> (control_l & 7)) & 1)
||((key_map_stat[control_r >> 3] >> (control_r & 7)) & 1));
}
#else
//ASSERT_(false, "Get key state is not implemented for this plathform")
#endif
return false;
}
It is first variant for get key state.
This method is missing in U++.
Any comments are welcome.
|
|
|
Goto Forum:
Current Time: Mon Jun 10 05:40:23 CEST 2024
Total time taken to generate the page: 0.01886 seconds
|