<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windows CE Programming &#187; hook</title>
	<atom:link href="http://www.hjgode.de/wp/tag/hook/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hjgode.de/wp</link>
	<description>Windows Mobile Development and usage</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:53:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<!--CodeProjectFeeder channel--><category>CodeProject</category><generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>KeyToggleStart: Yet another usage for keyboard hook</title>
		<link>http://www.hjgode.de/wp/2011/09/08/keytogglestart-yet-another-usage-for-keyboard-hook/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=keytogglestart-yet-another-usage-for-keyboard-hook</link>
		<comments>http://www.hjgode.de/wp/2011/09/08/keytogglestart-yet-another-usage-for-keyboard-hook/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 10:56:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[function keys]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=1204</guid>
		<description><![CDATA[Hello Windows Mobile Users recently the following was requested: How can I start an application by just hitting some keys in sequence? The answer: Just use a keyboard hook. So I started to code this hook tool based on my KeyToggleBoot2 code. There was not too much to change. The new tool is called KeyToggleStart [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Windows Mobile Users</p>
<p>recently the following was requested:</p>
<p>How can I start an application by just hitting some keys in sequence?</p>
<p>The answer: Just use a keyboard hook.</p>
<p>So I started to code this hook tool based on my KeyToggleBoot2 code. There was not too much to change. The new tool is called KeyToggleStart and it is configured by the registry:</p>
<pre>            REGEDIT4

            [HKEY_LOCAL_MACHINE\Software\Intermec\KeyToggleStart]
            "ForbiddenKeys"=hex:\
                  72 73 00
            ;max 10 keys!
            "KeySeq"="123"
            "Timeout"=dword:00000003
            "LEDid"=dword:00000001
            "Exe"="\\Windows\\iexplore.exe"
            "Arg"=""</pre>
<h2>Reg keys meaning:</h2>
<p><strong>Forbiddenkeys</strong> is just an addon feature: key codes entered in this list will not be processed any more by your Windows Mobile device. For example, to disable the use of the F3(VK_TTALK) and F4 (VK_TEND) keys you have to enter a binary list of 0&#215;72,0&#215;73,0&#215;00 (the zero is needed to terminate the list).</p>
<p><strong>KeySeq</strong> list the char sequence you want to use to start an application. For example if this is the string &#8220;123&#8243;, everytime you enter 123 in sequence within the given time, the application defined will be started.</p>
<p><strong>TimeOut</strong> is the time in seconds you have to enter the sequence. So do not use a long key sequence as &#8220;starteiexplorenow&#8221; and a short timeout (except you are a very fast type writer). The timeout is started with the first char matching and ends after the time or when you enter a non-matching char of the sequence.</p>
<p>With <strong>LEDid</strong> you can specify a LED index number. LED&#8217;s on Windows Mobile are controlled by an index number, each LED has one or more ID assigned to it. So, with LEDid you can control, which LED will lit, when the matching process is running. You can even find an ID to control a vibration motor, if your Windows Mobile device is equipped with one.</p>
<p>The <strong>Exe</strong> registry string value is used to specify which application will be started when the key sequence is matched.</p>
<p>If the application you want have to be started needs some arguments, you can enter these using the <strong>Arg</strong> registry value.</p>
<p>When you start the KeyToggleStart tool, you will not see any window except for a notification symbol on your Start/Home screen of the device.</p>
<p><a href="http://www.hjgode.de/wp/2011/09/08/keytogglestart-yet-another-usage-for-keyboard-hook/keytogglestart/" rel="attachment wp-att-1205"><img class="alignnone size-medium wp-image-1205" title="KeyToggleStart" src="http://www.hjgode.de/wp/wp-content/uploads/2011/09/KeyToggleStart-225x300.png" alt="" width="225" height="300" /></a></p>
<p>If you tap this icon (redirection sign) you have the chance to end the hook tool.</p>
<p><span id="more-1204"></span>The code itself is nothing special. Only the sequence matching code is a little bit special. As the chars in the sequence do not match keystrokes in a ont-to-one manner, I have to check the shift state of the keyboard and if the current char of the seqeunce is a char needing a shift. For example: the asterisk char (&#8220;*&#8221;) is a combination of the &#8220;8&#8243; key plus the Shift key. So, if you have the &#8220;*&#8221; in the char sequence, the code has to check for the &#8220;8&#8243; key and if the keyboard is in shift state:</p>
<pre lang="cpp">// 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-&gt;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-&gt;vkCode)
                {
                    bForbidden=true;
                    DEBUGMSG(1, (L"suppressing forbidden key: 0x%0x\n",pkbhData-&gt;vkCode));
                    continue;
                }
                j++;
            }while(!bForbidden &amp;&amp; pForbiddenKeyList[j]!=0x00);
            if(bForbidden){
                return true;
            }
        }

        SHORT sShifted = GetAsyncKeyState(VK_SHIFT);
        if((sShifted &amp; 0x800) == 0x800)
            isShifted = true;
        else
            isShifted = false;

        //check and toggle for Shft Key
        //do not process shift key
        if (pkbhData-&gt;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-&gt;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"---&gt; szVKeySeq[iMatched] = 0x%02x\n", (byte)szVKeySeq[iMatched]));

            if ( ((byte)pkbhData-&gt;vkCode == (byte)szVKeySeq[iMatched]) &amp;&amp; (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);
}</pre>
<p>Enjoy the code</p>
<p>Download VS2008 Source code for Windows Mobile 6.5.3 SDK<br />
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=143" title="Downloaded 90 times">KeyToggleStart</a> -  (Hits: 90, size: 30.06 kB)</p>
<p>Download KeyToggleStart executable (Windows Mobile 6)<br />
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=144" title="Downloaded 78 times">KeyToggleStart WM6 Executable</a> -  (Hits: 78, size: 12.38 kB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F&amp;title=KeyToggleStart%3A+Yet+another+usage+for+keyboard+hook" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F&amp;title=KeyToggleStart%3A+Yet+another+usage+for+keyboard+hook" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F&amp;title=KeyToggleStart%3A+Yet+another+usage+for+keyboard+hook" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F&amp;T=KeyToggleStart%3A+Yet+another+usage+for+keyboard+hook" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2011%2F09%2F08%2Fkeytogglestart-yet-another-usage-for-keyboard-hook%2F&amp;t=KeyToggleStart%3A+Yet+another+usage+for+keyboard+hook" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2011/09/08/keytogglestart-yet-another-usage-for-keyboard-hook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Development: Disable Windows Mobile 6.5 Start and Close Button</title>
		<link>http://www.hjgode.de/wp/2010/11/18/mobile-development-disable-windows-mobile-6-5-start-and-close-button/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mobile-development-disable-windows-mobile-6-5-start-and-close-button</link>
		<comments>http://www.hjgode.de/wp/2010/11/18/mobile-development-disable-windows-mobile-6-5-start-and-close-button/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 13:03:47 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[kiosk mode]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[6.5.3]]></category>
		<category><![CDATA[Close Button]]></category>
		<category><![CDATA[DotNet]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[sender-as-rectangle-windows-ce]]></category>
		<category><![CDATA[Start Button]]></category>
		<category><![CDATA[Subclassing]]></category>
		<category><![CDATA[taskbar]]></category>
		<category><![CDATA[windows mobile]]></category>
		<category><![CDATA[WM65]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=888</guid>
		<description><![CDATA[Windows Mobile 6.5.3. Class to subclass menu toolbar to disable Start and Close button clicks.]]></description>
			<content:encoded><![CDATA[<p>Hello</p>
<p>here is one other way to write a kios mode .NET application using a technique called SubClassing. The idea was born by a comment of redwolf2222 on this blog about how to <a href="http://www.hjgode.de/wp/2010/10/11/windows-mobile-hide-startbutton-in-winmo-6-5-x/">Hide Start and Close buttons on Windows Mobile 6.5 devices</a>. Redwolf2222 also provided a code snippet. Unfortunately it was incomplete and so I wrote my own class.</p>
<p><strong>Disable clicks on Start and Close button</strong></p>
<p>The demo project shows one dialog with two check boxes and you can easily test the function. If &#8220;StartButton Disabled&#8221; or &#8220;Close Button disabled&#8221; is checked, you cannot &#8216;click&#8217; the corresponding button any more:</p>
<p><a rel="attachment wp-att-889" href="http://www.hjgode.de/wp/2010/11/18/mobile-development-disable-windows-mobile-6-5-start-and-close-button/startbuttoncontrolwm65_2/"><img class="alignnone size-medium wp-image-889" title="StartButtonControlWM65" src="http://www.hjgode.de/wp/wp-content/uploads/2010/11/StartButtonControlWM65_2-225x300.gif" alt="" width="225" height="300" /></a></p>
<p>You still &#8216;click&#8217; the buttons but the subclassed window will not &#8216;execute&#8217; your click. The buttons are part of the toolbar32 window which is a child of the menu_worker window. So first we have to follow the window tree.</p>
<p><strong>Find the right window</strong></p>
<pre escaped="true" line="1" lang="csharp">/// &lt;summary&gt;
/// SubClassing: Install the wndproc hook
/// &lt;/summary&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private bool hookWindow()
{
    //find taskbar
    IntPtr hWndTaskbar = FindWindow("HHTaskbar", IntPtr.Zero);
    if (hWndTaskbar == IntPtr.Zero)
        return false;
    //enable the taskbar, not realy necessary
    EnableWindow(hWndTaskbar, true);
    //already installed?
    if (oldWndProc == IntPtr.Zero)
    {
        //find the menu_worker window
        IntPtr hwndMenu_Worker = FindWindow("menu_worker", IntPtr.Zero);
        if (hwndMenu_Worker != IntPtr.Zero)
        {
            //get the child window which has the buttons on it
            IntPtr hwndToolbar = GetWindow(hwndMenu_Worker, GetWindow_Cmd.GW_CHILD);
            if (hwndToolbar != IntPtr.Zero)
            {
                _mHwnd = hwndToolbar;       //store to remember
                SubclassHWnd(hwndToolbar);  //subclass the wndproc
            }
        }
    }
    return true;
}
</pre>
<p><strong>Subclassing</strong></p>
<p>Now, as we have the window handle, the subclassing can be started:<br />
 <span id="more-888"></span></p>
<pre escaped="true" line="1" lang="csharp">private void SubclassHWnd(IntPtr hWnd)
{
    // hWnd is the window you want to subclass..., create a new
    // delegate for the new wndproc
    newWndProc = new Win32WndProc(MyWndProc);
    // subclass
    oldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, newWndProc);
}
</pre>
<p>The installation of the &#8216;hook&#8217; is very simple. Just use SetWindowLong with the new window procedure. The old, original window procedure is saved for later use. We need it for example to call it for clicks outside the buttons and for all messages we don&#8217;t care about.</p>
<p>The &#8216;hook&#8217; or better the redirection will remain active until you install the old window procedure. So your device&#8217;s start and close button will not &#8216;work&#8217; as long as the hook is in place.</p>
<p><strong>The new window procedure</strong></p>
<pre escaped="true" line="1" lang="csharp">// this is the new wndproc, just show a messagebox on left button down:
private IntPtr MyWndProc(IntPtr hWnd, int msg, int wParam, int lParam)
{
    //is this a message for us?
    if (((msg == (int)WM_LBUTTONDOWN) || (msg == (int)WM_LBUTTONUP)) &amp;&amp; (this._mIsStartButtonDisabled || this._mIsCloseButtonDisabled) )
    {
        int x = ((int)lParam) &amp; 0xFFFF;
        int y = ((int)lParam) &gt;&gt; 16;

        bool isVGA;
        bool isQVGA;
        using (System.Windows.Forms.Control detector = new System.Windows.Forms.Control())
        {
            using (System.Drawing.Graphics gr = detector.CreateGraphics())
            {
                isVGA = gr.DpiY == 192;
                isQVGA = gr.DpiY == 96;
            }
        }

        RECT rect;
        GetWindowRect(hWnd, out rect); //get the rectangle of the menu_bar

        int width = Math.Max(rect.Left, rect.Right) - Math.Min(rect.Left, rect.Right);
        int height = Math.Max(rect.Bottom, rect.Top) - Math.Min(rect.Bottom, rect.Top);

        //width values are assumed
        int buttonWidth = (isQVGA | isVGA) ? 92 : 46;
        int buttonHeight = height; //(isQVGA | isVGA) ? 72 : 36;

        System.Drawing.Rectangle rectStartButton = new System.Drawing.Rectangle(0, 0, buttonWidth, buttonHeight);
        System.Drawing.Rectangle rectCloseButton = new System.Drawing.Rectangle(width - buttonWidth, 0, buttonWidth, buttonHeight);

        //check if enabled and click is inside the start or close button rectangle
        if(this._mIsStartButtonDisabled &amp;&amp; rectStartButton.Contains(x, y))
            return IntPtr.Zero;
        if (this._mIsCloseButtonDisabled &amp;&amp; rectCloseButton.Contains(x, y))
            return IntPtr.Zero;

        //if both are false, we have to provide the click to windows
        return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam);
    }
    else
        return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam);
}
</pre>
<p>Subclassing the window means that we redirect the window message procedure of the found window to our own, custom window procedure. This new procedure checks for WM_LBUTTONDOWN and WM_LBUTTONUP messages. Then the click position is checked and discarded if within the rectangle area of the Start and/or Close button. If the position is outside the calculated rectangles, the original window procedure is called.</p>
<p><strong>The demo code</strong></p>
<pre escaped="true" line="1" lang="csharp">public partial class StartButtonControl : Form
{
    StartButtonWM65.hwndutils _hwndutils = new StartButtonWM65.hwndutils();
    private bool _bInitializing = true;
    public StartButtonControl()
    {
        InitializeComponent();
        this.chkDisableStartButton.Checked = this._hwndutils.StartButtonDisabled;
        _bInitializing = false;
    }

    private void chkDisableStartButton_CheckStateChanged(object sender, EventArgs e)
    {
        if (_bInitializing)
            return;
        this._hwndutils.StartButtonDisabled = chkDisableStartButton.Checked;
    }

    private void mnuExit_Click(object sender, EventArgs e)
    {
        _hwndutils.Dispose();
        Application.Exit();
    }

    private void StartButtonControl_Closing(object sender, CancelEventArgs e)
    {
        _hwndutils.Dispose();
        Application.Exit();
    }

    private void chkCloseButton_CheckStateChanged(object sender, EventArgs e)
    {
        if (_bInitializing)
            return;
        this._hwndutils.CloseButtonDisabled = chkCloseButton.Checked;
    }
}
</pre>
<p>As you see, the usage of the class hwndutils is very simple. Dont forget to Dispose the hwndutils object before you exit your app.</p>
<p><strong>Downloads</strong><br />
 Visual Studion 2008 solution with demo project targeting Windows Mobile 6 SDK: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=128" title="Downloaded 831 times">StartButtonHookWM65 VS2008 source code and demo project</a> -  (Hits: 831, size: 18.53 kB)</p>
<p>Thanks to redwolf2222 for the great idea.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F&amp;title=Mobile+Development%3A+Disable+Windows+Mobile+6.5+Start+and+Close+Button" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F&amp;title=Mobile+Development%3A+Disable+Windows+Mobile+6.5+Start+and+Close+Button" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F&amp;title=Mobile+Development%3A+Disable+Windows+Mobile+6.5+Start+and+Close+Button" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F&amp;T=Mobile+Development%3A+Disable+Windows+Mobile+6.5+Start+and+Close+Button" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F11%2F18%2Fmobile-development-disable-windows-mobile-6-5-start-and-close-button%2F&amp;t=Mobile+Development%3A+Disable+Windows+Mobile+6.5+Start+and+Close+Button" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/11/18/mobile-development-disable-windows-mobile-6-5-start-and-close-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mobile Development: Hooking the keyboard &#8211; KeyToggle</title>
		<link>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mobile-development-hooking-the-keyboard-keytoggle</link>
		<comments>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 04:02:33 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Int*rm*c]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[function keys]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[simulate keys]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=675</guid>
		<description><![CDATA[Using keyboard hook to remap keys to function keys on windows mobile.]]></description>
			<content:encoded><![CDATA[<p><strong>KeyToggle</strong></p>
<p>Extend your keyboard to get function keys by pressing numbers.</p>
<p>With keytoggle you can define a &#8216;sticky&#8217; key that will change the beahviour of the number keys. As long as the sticky key is &#8216;active&#8217;, number keys from 1 to 0 will produce the function keys F1 to F10. If sticky key is active, the left LED will light in green.</p>
<p>To start keytoggle just tap it or let it start by a link in StartUp. If keytoggle is loaded, you can see a small yellow arrow sign in the taskbar.</p>
<p><a rel="attachment wp-att-676" href="http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/keytoggle-3/"><img class="alignnone size-full wp-image-676" title="keytoggle" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/keytoggle.gif" alt="" width="23" height="24" /></a></p>
<p>If you tap this symbol, you are asked, if you want to unload the app. If the registry does not have values defined for keytoggle, it will use default values. If you try to launch keytoggle a second time you will get a message box. Only one instance of keytoggle can run at a time.</p>
<p>Using the registry you can define the behaviour of the sticky key. In example, you can have the sticky key remain active until it is pressed again, let it &#8216;go off&#8217; or &#8216;fallback&#8217; after a period of time or let it fallback after a number key has been pressed. If the sticky key is pressed again, it will always fallback.</p>
<p><span id="more-675"></span>REGEDIT4<br />
 [HKEY<em>LOCAL</em>MACHINE\SOFTWARE\Intermec\KeyToggle]<br />
 &#8220;Timeout&#8221;=dword:00000000<br />
 &#8220;autoFallback&#8221;=dword:00000001<br />
 &#8220;StickyKey&#8221;=dword:00000090</p>
<p>The values:</p>
<pre><code>  StickyKey:
  default "144", decimal (VK_NUMLOCK)
  the VK_ value of the sticky key. Here you define, what you will have as the sticky key. VK_ values are defined as in winuser.h. In example the VK_ value for the NumLock key is 0x90 (144 decimal, see VK_NUMLOCK). The sticky key will be consumed by keytoggle and is not visible to the system any more. That means, that you should choose key value that you do not need in any app you use.

  Timeout:
  default "3", three seconds
  number of seconds the sticky key will remain active. If 0, the sticky key will not fallback automatically by time

  autoFallback:
  default "0"
  if 0 the sticky key will not fallback after pressing a number key. If 1 the sticky key will fallback after a number key is pressed
</code></pre>
<p><strong>Launch arguments</strong></p>
<pre><code>  Keytoggle only supports one argument: "-writereg". This will create the registry keys used by keytoggle and fill them with the default values.
</code></pre>
<p><strong>Usage Sample Scenario</strong></p>
<p>You have a ITC Color device  with a numeric keyboard but no function keys. You need the function keys to be able to use a web application within iBrowse. With keytoggle you can now for example use the Gold key as sticky key. You have to download the device reource kit to get a keyboard remapper tool from the ITC site and assign the Gold key to NUMLOCK.</p>
<p><a rel="attachment wp-att-677" href="http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/cpkbdmap-3/"><img class="alignnone size-medium wp-image-677" title="cpkbdmap" src="http://www.hjgode.de/wp/wp-content/uploads/2010/07/cpkbdmap-225x300.gif" alt="" width="225" height="300" /></a></p>
<p>With this remapping and keytoggle running you will to get a function keystroke simulated if you press the Gold key and then a number key.</p>
<p>Download installer: <b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=107" title="Downloaded 194 times">KeyToggle Installer CAB</a> -  (Hits: 194, size: 5.19 kB)</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;title=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;T=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2010%2F07%2F16%2Fmobile-development-hooking-the-keyboard-keytoggle%2F&amp;t=Mobile+Development%3A+Hooking+the+keyboard+%26%238211%3B+KeyToggle" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2010/07/16/mobile-development-hooking-the-keyboard-keytoggle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hooking the keyboard message queue in compact framework code</title>
		<link>http://www.hjgode.de/wp/2009/12/04/hooking-the-keyboard-message-queue-in-compact-framework-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hooking-the-keyboard-message-queue-in-compact-framework-code</link>
		<comments>http://www.hjgode.de/wp/2009/12/04/hooking-the-keyboard-message-queue-in-compact-framework-code/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 21:26:03 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cf2]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[hooking]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[windows mobile]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=240</guid>
		<description><![CDATA[Hooking the keyboard message queue in CF2]]></description>
			<content:encoded><![CDATA[<p>Here is some nice code to use a keyboard hook implemented in C# for compact framework.</p>
<p>You can use this to catch the funny OS asigned keys like F1, F2, F3, F4, F6 and F7 (Softkey 1 and 2, Phone, End, Volume Up, Volume Down); and last but not least catch the Win Key press.</p>
<p><span id="more-240"></span>The hooking class:</p>
<pre lang="csharp">using System;
using System.Runtime.InteropServices;
/*
In order to use this class in your program, just declare the varialble and hook up into HookEvent:
HookKeys hook = new HookKeys();
hook.HookEvent += new HookKeys.HookEventHandler(HookEvent);
hook.Start();
*/
public class HookKeys
{
#region delegates
    public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
    public delegate void HookEventHandler(HookEventArgs e, KeyBoardInfo keyBoardInfo);
    public HookEventHandler HookEvent;
#endregion
#region fields
    private HookProc hookDeleg;
    private static int hHook = 0;
#endregion

    public HookKeys()
    {
    }
    ~HookKeys(){
        if(hHook!=0)
            this.Stop();
    }
    #region public methods
    ///
    /// Starts the hook
    ///
    public void Start()
    {
        if (hHook != 0)
        {
            //Unhook the previouse one
            this.Stop();
        }
        hookDeleg = new HookProc(HookProcedure);
        hHook = SetWindowsHookEx(WH_KEYBOARD_LL, hookDeleg, GetModuleHandle(null), 0);
        if (hHook == 0)
        {
            throw new SystemException("Failed acquiring of the hook.");
        }
        AllKeys(true);
    }
    ///
    /// Stops the hook
    ///
    public void Stop()
    {
        UnhookWindowsHookEx(hHook);
        AllKeys(false);
    }
    #endregion
    #region protected and private methods
    protected virtual void OnHookEvent(HookEventArgs hookArgs, KeyBoardInfo keyBoardInfo)
    {
        if (HookEvent != null)
        {
            HookEvent(hookArgs, keyBoardInfo);
        }
    }

    private int HookProcedure(int code, IntPtr wParam, IntPtr lParam)
    {
       KBDLLHOOKSTRUCT hookStruct =  (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
       if (code &lt; 0)
            return CallNextHookEx(hookDeleg, code, wParam, lParam);
       // Let clients determine what to do
       HookEventArgs e = new HookEventArgs();
       e.Code = code;
       e.wParam = wParam;
       e.lParam = lParam;
       KeyBoardInfo keyInfo = new KeyBoardInfo();
       keyInfo.vkCode = hookStruct.vkCode;
       keyInfo.scanCode = hookStruct.scanCode;
       OnHookEvent(e, keyInfo);
       // Yield to the next hook in the chain
       return CallNextHookEx(hookDeleg, code, wParam, lParam);
   }
   #endregion
   #region P/Invoke declarations

   [DllImport("coredll.dll")]
   private static extern int AllKeys(bool bEnable);

   [DllImport("coredll.dll")]
   private static extern int SetWindowsHookEx(int type, HookProc hookProc, IntPtr hInstance, int m);
   [DllImport("coredll.dll")]
   private static extern IntPtr GetModuleHandle(string mod);
   [DllImport("coredll.dll")]
   private static extern int CallNextHookEx(
           HookProc hhk,
           int nCode,
           IntPtr wParam,
           IntPtr lParam
           );
   [DllImport("coredll.dll")]
   private static extern int GetCurrentThreadId();
   [DllImport("coredll.dll", SetLastError = true)]
   private static extern int UnhookWindowsHookEx(int idHook);
   private struct KBDLLHOOKSTRUCT
   {
       public int vkCode;
       public int scanCode;
       public int flags;
       public int time;
       public IntPtr dwExtraInfo;
   }
   const int WH_KEYBOARD_LL = 20;
   #endregion
}
#region event arguments

    public class HookEventArgs : EventArgs
    {
        public int Code;    // Hook code
        public IntPtr wParam;   // WPARAM argument
        public IntPtr lParam;   // LPARAM argument
    }
    public class KeyBoardInfo
    {
        public int vkCode;
        public int scanCode;
        public int flags;
        public int time;
    }
#endregion
</pre>
<p>Here is the download of the Visual Studio 2005 Windows Mobile 6 SDK targeting source code:</p>
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=46" title="Downloaded 1025 times">KbdHookCS</a> - Keyboard hooking in compact framework (Hits: 1025, size: 31.69 KB)
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F&amp;title=Hooking+the+keyboard+message+queue+in+compact+framework+code" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F&amp;title=Hooking+the+keyboard+message+queue+in+compact+framework+code" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F&amp;title=Hooking+the+keyboard+message+queue+in+compact+framework+code" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F&amp;T=Hooking+the+keyboard+message+queue+in+compact+framework+code" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F12%2F04%2Fhooking-the-keyboard-message-queue-in-compact-framework-code%2F&amp;t=Hooking+the+keyboard+message+queue+in+compact+framework+code" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2009/12/04/hooking-the-keyboard-message-queue-in-compact-framework-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hooking into the keyboard message queue</title>
		<link>http://www.hjgode.de/wp/2009/05/16/hooking-into-the-keyboard-message-queue/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hooking-into-the-keyboard-message-queue</link>
		<comments>http://www.hjgode.de/wp/2009/05/16/hooking-into-the-keyboard-message-queue/#comments</comments>
		<pubDate>Sat, 16 May 2009 04:59:09 +0000</pubDate>
		<dc:creator>josef</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[kiosk mode]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[iHook]]></category>
		<category><![CDATA[keyb-exe-for-win-ce]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[windows ce]]></category>

		<guid isPermaLink="false">http://www.hjgode.de/wp/?p=52</guid>
		<description><![CDATA[Sample source for windows ce showwing how to use keyboard hooks in windows ce]]></description>
			<content:encoded><![CDATA[<p>Although undocumented keyboard hooking is possible. I read an article at <a title="Using keyboard hooks in windows ce" href="http://www.codeproject.com/KB/mobile/wincekbhook.aspx">CodeProject</a> about hooking and wrote some applications that uses this great possibility. One result is iHook, an application that will do something like the button shortcuts applet in windows mobile. You can define keys and what application they should start.</p>
<h2><a name="iHook2"><span id="more-52"></span>iHook3</a></h2>
<p>This application provides the user with key shortcuts to applications. All keystrokes or hot keys are transparent, this means, they are not lost  and will reach the application just running in foreground. iHook2 can be started  by placing a link to the exe in \Windows\Startup, by a batch file or some other  AutoStart feature of the device OS.</p>
<h2><!--more-->iHook3 Version 1.3</h2>
<p>This versions uses the registry to read the assigned keys and applications.  Additionally the app is now safe and will only load once. The only argument  supported is &#8220;-writereg&#8221; to write a default registry (see below).</p>
<h3>Sample registry:</h3>
<pre>[HKEY_LOCAL_MACHINE\SOFTWARE\Intermec\iHook2]
"arg4"="iRun2.exe"
"exe4"="\\windows\\iKill2.exe"
"key4"=hex:\
      1b
"arg3"=""
"exe3"="explorer.exe"
"key3"=hex:\
      71
"arg2"=""
"exe2"="\\windows\\iSIP2.exe"
"key2"=hex:\
      74
"arg1"="-toggle"
"exe1"="\\windows\\LockTaskBar.exe"
"key1"=hex:\
      73
"arg0"=""
"exe0"="\\windows\\iRotateCN2.exe"
"key0"=hex:\
      72</pre>
<h2><a name="iHook3"></a></h2>
<p><strong>New in version iHook3 (version 2.0)</strong><br />
recognizes CK60<br />
adds Notification icon in taskbar</p>
<p><strong>New in iHook3 (version 3.1)</strong><br />
recognizes CN3<br />
supports consuming/forwarding switch for hot-keys. Use &#8220;ForwardKey&#8221;  registry binary value 0 to disable forwarding hot-keys, 1 to enable forwarding  hotkeys.<br />
This new option is usefull if you have a phone device and hook the number keys.  In this case disable forwarding with 0, otherwise the phone app will come in  front for the number keys.</p>
<pre>REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Intermec\iHook3]
"arg0"=""
"exe0"="\\Windows\\iRotate.exe"
"key0"=hex:\
      26
"<strong>ForwardKey</strong>"=hex:\
      00

<strong>The main functionality is in here:</strong>
#pragma data_seg(".HOOKDATA")									//	Shared data (memory) among all instances.
	HHOOK g_hInstalledLLKBDhook = NULL;						// Handle to low-level keyboard hook
	//HWND hWnd	= NULL;											// If in a DLL, handle to app window receiving WM_USER+n message
#pragma data_seg()

#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")		//linker directive

// 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;
	PROCESS_INFORMATION pi;
	int i;
	bool processed_key=false;
	if (nCode == iActOn)
	{
		PKBDLLHOOKSTRUCT pkbhData = (PKBDLLHOOKSTRUCT)lParam;
		if ( (wParam == WM_KEYUP) &amp;&amp; (processed_key==false) )
		{
			for (i=0; i&lt;=lastKey; i++)
			{
				if (pkbhData-&gt;vkCode == kMap[i].keyCode)
				{

Below is the download of the source code as done with embedded visual c 4.
<b>DOWNLOAD:</b><a href="http://www.hjgode.de/wp/wp-content/plugins/download-monitor/download.php?id=6" title="Downloaded 340 times">iHook3 Embedded Visual C++ 4 source code</a> -  (Hits: 340, size: 90.75 KB)</pre>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F&amp;title=Hooking+into+the+keyboard+message+queue" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F&amp;title=Hooking+into+the+keyboard+message+queue" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F&amp;title=Hooking+into+the+keyboard+message+queue" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F&amp;T=Hooking+into+the+keyboard+message+queue" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.hjgode.de%2Fwp%2F2009%2F05%2F16%2Fhooking-into-the-keyboard-message-queue%2F&amp;t=Hooking+into+the+keyboard+message+queue" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.hjgode.de/wp/wp-content/plugins/social-bookmarks0/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.hjgode.de/wp/2009/05/16/hooking-into-the-keyboard-message-queue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

