捕获Windows Mobile设备中的按键序列

本文关键字:Windows Mobile 捕获 | 更新日期: 2023-09-27 18:09:44

我需要从Windows Mobile设备捕获按键序列以触发胁迫事件。如果我的应用程序是唯一运行的东西,我会使用基本形式的事件处理程序来检查按键但是…由于应用程序可以启动浏览器并使用SOTI,因此它也必须在主应用程序之外工作。

是否有可能在Windows Mobile设备上创建一个TSR应用程序,可以发送web服务消息(同时在通信中)?

捕获Windows Mobile设备中的按键序列

我已经编写了几个调用不同函数的键盘钩子'应用程序'。您还可以使用它来执行套接字或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个文本框的空项目,包括以下文件并添加这段代码:

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专业版