0

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

是否可以在 Windows Mobile 设备上创建可以发送 Web 服务消息(在通信中)的 TSR 应用程序?

4

2 回答 2

1

我已经编写了几个调用不同功能的键盘挂钩“应用程序”。您还可以使用它来进行套接字或 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 上)。

于 2013-04-18T16:49:02.920 回答
0

我最近需要从手持设备获取密钥代码,我刚刚创建了一个带有 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专业人士工作

于 2017-05-08T14:40:54.403 回答