void OS_SYSTEM_EventPreHandler(void *void_event){ MSG *msg = (MSG*)void_event; switch(msg->message){ case WM_NCACTIVATE: g_bWindowActive = msg->wParam ? true : false; //printf("1. Got NC Activate. wParam: %d\n",(int)msg->wParam); //fflush(stdout); break; case WM_ACTIVATE: g_bWindowActive = msg->wParam ? true : false; //printf("2. Got Activate. wParam: %d\n",(int)msg->wParam); //fflush(stdout); break; case WM_ACTIVATEAPP: g_bWindowActive = msg->wParam ? true : false; //printf("3. Got Activate app. wParam: %d\n",(int)msg->wParam); //fflush(stdout); break; } int type = OS_SYSTEM_get_event_type(void_event, true); if (type==TR_KEYBOARD || type==TR_KEYBOARDUP){ g_last_keyswitch = tevent.keyswitch; tevent.keyswitch = get_keyswitch(); } }
bool SystemEventFilter(void *event){ OS_SYSTEM_EventPreHandler(event); MSG *msg = (MSG*)event; int type = OS_SYSTEM_get_event_type(event, true); if (type!=-1){ int keynum = OS_SYSTEM_get_keynum(event); int qwerty = OS_SYSTEM_get_qwerty_keynum(event); printf("Got %s event: %d / %d. swiktch: %x. wparam: 0x%x. Modifier: %d. Autorepeat: %s\n", type==TR_KEYBOARD?"press":"release",keynum,qwerty,get_keyswitch(),msg->wParam,OS_SYSTEM_get_modifier(event),type==TR_AUTOREPEAT?"true":"false" ); } return false; }
bool OS_SYSTEM_KeyboardFilter(void *focused_widget, void *void_msg){ MSG *msg = void_msg; static int last_pressed_key = -1; static int64_t last_pressed_key_time = -1; static int last_pressed_keyswitch = -1; struct Tracker_Windows *window=root->song->tracker_windows; #if 0 static int num=0; if(msg->message!=WM_TIMER && msg->message!=0x84 && msg->message!=WM_MOUSEFIRST && msg->message!=WM_MOUSEMOVE && msg->message!=WM_SETCURSOR){ char *temp=""; printf("Got something. Message: 0x%x. wParam: 0x%x. lParam: 0x%x. Num: %d. Name: \"%s\", Left shift? 0x%x\n",(int)msg->message,(int)msg->wParam,(int)msg->lParam,num++,temp,(int)GetKeyState(VK_LSHIFT)); fflush(stdout); } #endif switch(msg->message){ case WM_HOTKEY: //printf("Got HotKey\n"); //fflush(stdout); return true; case WM_KEYDOWN: case WM_SYSKEYDOWN: if(num_users_of_keyboard>0) return false; tevent.ID=TR_KEYBOARD; tevent.SubID=get_keyboard_subID(msg); last_pressed_key = tevent.SubID; if(last_pressed_key_time==-1) last_pressed_key_time = MIXER_get_time(); tevent.keyswitch=get_keyswitch(); last_pressed_keyswitch = tevent.keyswitch; /* printf("____________ key down: %x. Switch down: %x, left ctrl: %x, left alt: %x, right ctrl: %x, right alt: %x\n", last_pressed_key,last_pressed_keyswitch, EVENT_LEFTCTRL, EVENT_LEFTALT, EVENT_RIGHTCTRL, EVENT_RIGHTALT ); */ EventReciever(&tevent,window); return true; case WM_KEYUP: case WM_SYSKEYUP: if(msg->wParam==VK_RWIN){ right_windows_down = false; return false; } if(msg->wParam==VK_LWIN){ left_windows_down = false; return false; } if(num_users_of_keyboard>0) return false; int keynum = get_keyboard_subID(msg); tevent.ID=TR_KEYBOARDUP; tevent.SubID=keynum; tevent.keyswitch=get_keyswitch(); int64_t time_now = MIXER_get_time(); //printf("____________ key: %x. Switch down: %x, Switch up: %x\n",keynum,last_pressed_keyswitch,tevent.keyswitch); //printf("keynum: %d, last_pressed: %d, ALT_R: %d, time_now: %d, last_time: %d, diff: %d\n",keynum,last_pressed_key,EVENT_ALT_R,(int)time_now,(int)last_pressed_key_time,(int)(time_now-last_pressed_key_time)); //fflush(stdout); if( (time_now-last_pressed_key_time) < pc->pfreq/4){ // i.e. only play if holding the key less than 0.25 seconds. bool isplaykeyswitch = (last_pressed_keyswitch & EVENT_RIGHTALT) || last_pressed_keyswitch==EVENT_RIGHTSHIFT; /* printf("****************** last_pressed_keyswitch: %x (%x) (%x) (%d)\n",last_pressed_keyswitch, EVENT_RIGHTALT, EVENT_LEFTALT|EVENT_LEFTCTRL, EVENT_RIGHTALT|EVENT_LEFTCTRL); printf("isplaykeyswitch: %d, keynum==last_pressed_key: %d, keynum==0: %d, (tevent.keyswitch==0: %d || (similar: %x/%x/%x))\n", isplaykeyswitch, keynum==last_pressed_key, keynum==0, tevent.keyswitch==0, tevent.keyswitch,EVENT_RIGHTALT,last_pressed_keyswitch); */ if (isplaykeyswitch) if(keynum==last_pressed_key && keynum==0 && (tevent.keyswitch==0 || (tevent.keyswitch==EVENT_RIGHTALT && EVENT_RIGHTALT==last_pressed_keyswitch))) PlayBlockFromStart(window,true); // true == do_loop } last_pressed_key_time = -1; EventReciever(&tevent,window); return true; default: break; } return false; }