c# - Capture keypress sequence in Windows Mobile device -
i need capture keypress sequence windows mobile device trigger duress event. if application thing running use base form event handler check keypress but... application launch browser , uses soti, must work outside of main application.
is possible create tsr application on windows mobile device can send web service messages (whilst in comms)?
i have written several keyboard hook 'applications' invoke different functions. can use socket or webservice calls: http://www.hjgode.de/wp/?s=hook , http://www.hjgode.de/wp/?s=keytoggle
// command below tells os exe has export function can use global hook without dll __declspec(dllexport) lresult callback g_llkeyboardhookcallback( int ncode, // hook code wparam wparam, // window message (wm_keyup, wm_keydown, etc.) lparam lparam // pointer struct information pressed key ) { /* typedef struct { dword vkcode; dword scancode; dword flags; dword time; ulong_ptr dwextrainfo; } kbdllhookstruct, *pkbdllhookstruct;*/ // out of hooks asap; no modal dialogs or cpu-intensive processes! // ui code should elsewhere, test/prototype app // in limited testing, hc_action value ncode ever set in ce static int iacton = hc_action; static bool isshifted=false; #ifdef debug static tchar str[max_path]; #endif pkbdllhookstruct pkbhdata = (pkbdllhookstruct)lparam; //dword vkey; if (ncode == iacton) { //only process unflagged keys if (pkbhdata->flags != 0x00) return callnexthookex(g_hinstalledllkbdhook, ncode, wparam, lparam); //check vkcode against forbidden key list if(pforbiddenkeylist!=null) { bool bforbidden=false; int j=0; do{ if(pforbiddenkeylist[j]==(byte)pkbhdata->vkcode) { bforbidden=true; debugmsg(1, (l"suppressing forbidden key: 0x%0x\n",pkbhdata->vkcode)); continue; } j++; }while(!bforbidden && pforbiddenkeylist[j]!=0x00); if(bforbidden){ return true; } } short sshifted = getasynckeystate(vk_shift); if((sshifted & 0x800) == 0x800) isshifted = true; else isshifted = false; //check , toggle shft key //do not process shift key if (pkbhdata->vkcode == vk_shift){ debugmsg(1, (l"ignoring vk_shift\n")); return callnexthookex(g_hinstalledllkbdhook, ncode, wparam, lparam); } //################################################################ //check if actual key match key including shift state if ((byte)pkbhdata->vkcode == (byte)szvkeyseq[imatched]){ debugmsg(1 , (l"==== char match\n")); if (bcharshiftseq[imatched] == isshifted){ debugmsg(1 , (l"==== shift match\n")); } else{ debugmsg(1 , (l"==== shift not match\n")); } } if( wparam == wm_keyup ){ debugmsg(1, (l"---> szvkeyseq[imatched] = 0x%02x\n", (byte)szvkeyseq[imatched])); if ( ((byte)pkbhdata->vkcode == (byte)szvkeyseq[imatched]) && (isshifted == bcharshiftseq[imatched]) ) { //the first match? if(imatched==0){ //start timer , lit led ledon(ledid,1); tid=settimer(null, 0, matchtimeout, (timerproc)timer2proc); } imatched++; debugmsg(1, (l"imatched now=%i\n", imatched)); //are keys matched if (imatched == ikeycount){ //show modeless dialog debugmsg(1, (l"full match, starting ...\n")); postmessage(g_hwnd, wm_showmydialog, 0, 0); //reset match pos , stop timer debugmsg(1, (l"full match: reset matching\n")); ledon(ledid,0); imatched=0; //reset match pos killtimer(null, tid); //return callnexthookex(g_hinstalledllkbdhook, ncode, wparam, lparam); } //return -1; //do not forward key? } else { killtimer(null, tid); ledon(ledid,0); imatched=0; //reset match pos debugmsg(1, (l"full match missed. reseting matching\n")); } } //if wparam == wm_key.. } return callnexthookex(g_hinstalledllkbdhook, ncode, wparam, lparam); }
looking hook example looks key sequence: http://code.google.com/p/keytoggleboot/source/browse/trunk/keytoggleboot/readme.txt?spec=svn14&r=14
there articles , posts keyboard hooks in internet (ie @ codeproject).
Comments
Post a Comment