<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Keyboard hook...' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Keyboard hook...' posted on the 'Windows programming' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sun, 26 May 2013 01:06:37 -0700</pubDate>
    <lastBuildDate>Sun, 26 May 2013 01:06:37 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Keyboard hook...</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/165233/keyboard-hook/</link>
      <description>Hi,&lt;br /&gt;
&lt;br /&gt;
this function is called:&lt;br /&gt;
&lt;br /&gt;
void SetKBHook(void)&lt;br /&gt;
{&lt;br /&gt;
KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookPro
c,hInst,0L);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
KH1 is 0, why? :(&lt;br /&gt;
-hInst is my app instance&lt;br /&gt;
-KHookProc is the correct HookProc&lt;br /&gt;
&lt;br /&gt;
hhheelllppp...&lt;br /&gt;
&lt;br /&gt;
cu,&lt;br /&gt;
&lt;br /&gt;
illuminator&lt;br /&gt;
(Novus ordo seclorum)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/165233/keyboard-hook/</guid>
      <pubDate>Wed, 15 Jan 2003 00:42:29 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Keyboard hook...</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/165265/re-keyboard-hook/#165265</link>
      <description>What OS? WH_KEYBOARD_LL does not work in 9x.&lt;br /&gt;
&lt;br /&gt;
Also, is this in an EXE or DLL? Because passing an hInstance should be done only with system-wide hooks that reside in a DLL. For a local hook in an EXE use:&lt;br /&gt;
KH1 = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KHookProc, NULL, GetCurrentThreadId());&lt;br /&gt;
&lt;br /&gt;
Which hooks the keyboard for the current process only.&lt;br /&gt;
&lt;br /&gt;
: Hi,&lt;br /&gt;
: &lt;br /&gt;
: this function is called:&lt;br /&gt;
: &lt;br /&gt;
: void SetKBHook(void)&lt;br /&gt;
: {&lt;br /&gt;
: KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookPro
c,hInst,0L);&lt;br /&gt;
: }&lt;br /&gt;
: &lt;br /&gt;
: KH1 is 0, why? :(&lt;br /&gt;
: -hInst is my app instance&lt;br /&gt;
: -KHookProc is the correct HookProc&lt;br /&gt;
: &lt;br /&gt;
: hhheelllppp...&lt;br /&gt;
: &lt;br /&gt;
: cu,&lt;br /&gt;
: &lt;br /&gt;
: illuminator&lt;br /&gt;
: (Novus ordo seclorum)&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/165265/re-keyboard-hook/#165265</guid>
      <pubDate>Wed, 15 Jan 2003 06:14:11 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Thx !! :)</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/165730/thx--/#165730</link>
      <description>Thx !! :)&lt;br /&gt;
&lt;br /&gt;
cu,&lt;br /&gt;
&lt;br /&gt;
illuminator&lt;br /&gt;
(Novus ordo seclorum)&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/165730/thx--/#165730</guid>
      <pubDate>Fri, 17 Jan 2003 09:02:49 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Additional question...</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/166272/additional-question/#166272</link>
      <description>Hi&lt;br /&gt;
&lt;br /&gt;
1. Thx. Your code works. :)&lt;br /&gt;
&lt;br /&gt;
2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:&lt;br /&gt;
&lt;br /&gt;
C:&lt;br /&gt;
typedef struct tagKBDLLHOOKSTRUCT {&lt;br /&gt;
    DWORD   vkCode;&lt;br /&gt;
    DWORD   scanCode;&lt;br /&gt;
    DWORD   flags;&lt;br /&gt;
    DWORD   time;&lt;br /&gt;
    DWORD   dwExtraInfo;&lt;br /&gt;
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;&lt;br /&gt;
&lt;br /&gt;
VB.Net:&lt;br /&gt;
Public Structure KBDLLHOOKSTRUCT&lt;br /&gt;
    Public vkCode As Integer&lt;br /&gt;
    Public scanCode As Integer&lt;br /&gt;
    Public flags As Integer&lt;br /&gt;
    Public time As Integer&lt;br /&gt;
    Public dwExtraInfo As Integer&lt;br /&gt;
End Structure&lt;br /&gt;
- Wrong :( Why? &lt;br /&gt;
&lt;br /&gt;
PS: you guys are great! ;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cu,&lt;br /&gt;
&lt;br /&gt;
illuminator&lt;br /&gt;
(Novus ordo seclorum)&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/166272/additional-question/#166272</guid>
      <pubDate>Mon, 20 Jan 2003 08:31:49 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Additional question...</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/166308/re-additional-question/#166308</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by pingpong at  2003-1-20 11:43:29&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
/edit Yikes, got my VB mixed up with C#. Why dont you use C# by the way?&lt;br /&gt;
&lt;br /&gt;
You need the StructLayout attribute thingy..&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
Imports System.Runtime.InteropServices

&amp;lt;StructLayout(LayoutKind.Sequential, Pack = 1)&amp;gt; _
Public Structure KBDLLHOOKSTRUCT
   Public vkCode As Integer
   Public scanCode As Integer
   Public flags As Integer
   Public time As Integer
   Public dwExtraInfo As Integer
End Structure
&lt;/pre&gt;&lt;br /&gt;
So .NET wont mess around with it and tries to optimize it. The pack=1 is standard Win32 API stuff.&lt;br /&gt;
&lt;br /&gt;
Dont know how are you going to make the LowLevelKeyboardProc work though, this might work:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
&amp;lt;DllImport("kernel32.dll")&amp;gt; _
Public Shared Function LowLevelKeyboardProc(nCode As Integer, wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
&lt;/pre&gt;&lt;br /&gt;
If it doesnt, it means that Windows is trying to send a NULL in the lParam, dont know how you fix that in VB.NET, in C# you can declare it as int lParam then do the appropriate cast in a fixed block.&lt;br /&gt;
&lt;br /&gt;
Good luck.&lt;br /&gt;
&lt;br /&gt;
: Hi&lt;br /&gt;
: &lt;br /&gt;
: 1. Thx. Your code works. :)&lt;br /&gt;
: &lt;br /&gt;
: 2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:&lt;br /&gt;
: &lt;br /&gt;
: C:&lt;br /&gt;
: typedef struct tagKBDLLHOOKSTRUCT {&lt;br /&gt;
:     DWORD   vkCode;&lt;br /&gt;
:     DWORD   scanCode;&lt;br /&gt;
:     DWORD   flags;&lt;br /&gt;
:     DWORD   time;&lt;br /&gt;
:     DWORD   dwExtraInfo;&lt;br /&gt;
: } KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;&lt;br /&gt;
: &lt;br /&gt;
: VB.Net:&lt;br /&gt;
: Public Structure KBDLLHOOKSTRUCT&lt;br /&gt;
:     Public vkCode As Integer&lt;br /&gt;
:     Public scanCode As Integer&lt;br /&gt;
:     Public flags As Integer&lt;br /&gt;
:     Public time As Integer&lt;br /&gt;
:     Public dwExtraInfo As Integer&lt;br /&gt;
: End Structure&lt;br /&gt;
: - Wrong :( Why? &lt;br /&gt;
: &lt;br /&gt;
: PS: you guys are great! ;)&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: cu,&lt;br /&gt;
: &lt;br /&gt;
: illuminator&lt;br /&gt;
: (Novus ordo seclorum)&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/166308/re-additional-question/#166308</guid>
      <pubDate>Mon, 20 Jan 2003 11:41:55 -0700</pubDate>
      <category>Windows programming</category>
    </item>
    <item>
      <title>Re: Additional question...</title>
      <link>http://www.programmersheaven.com/mb/windows/165233/166406/re-additional-question/#166406</link>
      <description>Hi&lt;br /&gt;
&lt;br /&gt;
thx again! :) &lt;br /&gt;
&lt;br /&gt;
&amp;lt;StructLayout(LayoutKind.Sequential)&amp;gt; _&lt;br /&gt;
Public Structure KBDLLHOOKSTRUCT&lt;br /&gt;
   Public vkCode As Integer&lt;br /&gt;
   Public scanCode As Integer&lt;br /&gt;
   Public flags As Integer&lt;br /&gt;
   Public time As Integer&lt;br /&gt;
   Public dwExtraInfo As Integer&lt;br /&gt;
End Structure&lt;br /&gt;
&lt;br /&gt;
"Pack = 1" was not accepted, because "StructLayout" only expects one parameter.&lt;br /&gt;
&lt;br /&gt;
cu,&lt;br /&gt;
&lt;br /&gt;
illuminator&lt;br /&gt;
(Novus ordo seclorum)&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/windows/165233/166406/re-additional-question/#166406</guid>
      <pubDate>Tue, 21 Jan 2003 00:39:15 -0700</pubDate>
      <category>Windows programming</category>
    </item>
  </channel>
</rss>