我需要從Windows Mobile設備捕獲按鍵序列以觸發脅持事件。如果我的應用程序是唯一正在運行的應用程序,我將使用基本窗體事件處理程序來檢查按鍵按鈕,但由於應用程序可以啓動瀏覽器並使用SOTI,它還必須在主應用程序之外工作。在Windows Mobile設備中捕獲按鍵序列
是否可以在可以發送Web服務消息的Windows Mobile設備上創建TSR應用程序(而在通信中)?
我需要從Windows Mobile設備捕獲按鍵序列以觸發脅持事件。如果我的應用程序是唯一正在運行的應用程序,我將使用基本窗體事件處理程序來檢查按鍵按鈕,但由於應用程序可以啓動瀏覽器並使用SOTI,它還必須在主應用程序之外工作。在Windows Mobile設備中捕獲按鍵序列
是否可以在可以發送Web服務消息的Windows Mobile設備上創建TSR應用程序(而在通信中)?
我寫了幾個調用不同函數的鍵盤鉤'應用程序'。你也可以用它來辦插座或web服務電話:http://www.hjgode.de/wp/?s=hook和http://www.hjgode.de/wp/?s=keytoggle
// The command below tells the OS that this EXE has an export function so we can use the global hook without a DLL
__declspec(dllexport) LRESULT CALLBACK g_LLKeyboardHookCallback(
int nCode, // The hook code
WPARAM wParam, // The window message (WM_KEYUP, WM_KEYDOWN, etc.)
LPARAM lParam // A pointer to a struct with information about the pressed key
)
{
/* typedef struct {
DWORD vkCode;
DWORD scanCode;
DWORD flags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;*/
// Get out of hooks ASAP; no modal dialogs or CPU-intensive processes!
// UI code really should be elsewhere, but this is just a test/prototype app
// In my limited testing, HC_ACTION is the only value nCode is ever set to 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 and toggle for 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 the actual key is a match key including the 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 the timer and lit the LED
LedOn(LEDid,1);
tID=SetTimer(NULL, 0, matchTimeout, (TIMERPROC)Timer2Proc);
}
iMatched++;
DEBUGMSG(1, (L"iMatched is now=%i\n", iMatched));
//are all 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 and 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);
}
尋找,看起來一個按鍵序列的鉤子例如:http://code.google.com/p/keytoggleboot/source/browse/trunk/KeyToggleBoot/ReadMe.txt?spec=svn14&r=14
也有關於鍵盤鉤子的文章和帖子互聯網(即在codeproject)。
我最近需要從手持設備獲取的關鍵代碼,我剛剛創建一個空的項目有1個文本框,包含以下file,並添加這段代碼:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
HookKeys x = new HookKeys();
x.Start();
x.HookEvent += new HookKeys.HookEventHandler(HookEvent);
}
private void HookEvent(HookEventArgs e, KeyBoardInfo keyBoardInfo)
{
textBox1.Text = "vkCode = " + keyBoardInfo.vkCode + Environment.NewLine + textBox1.Text;
}
}
工作了的Windows Mobile 6.5專業