Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Since I dont know which board to post a question in, I'll ask where to post it...

Since I dont know which board to post a question in, I'll ask where to post it...

Scheduled Pinned Locked Moved The Lounge
questioncsharphelp
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anton Afanasyev

    Where would I post a question about myself having a problem with keyboard hooking, using C#, running under Vista, and the whole thing not working when VMWare Workstation is the topmost window? Yes, I am serious. I really dont know which forum to post this to

    C Offline
    C Offline
    CataclysmicQuantum
    wrote on last edited by
    #3

    You would get better information in the C++ forum since hooks deal with the windows api.

    Word, write letters and sh*t yo. It takes 46 muscles to frown but only 4 to flip 'em the bird. Friendship is like peeing on yourself: everyone can see it, but only you get the warm feeling that it brings. The greatest pleasure in life is doing what people say you cannot do. Everyone needs believe in something. I believe I'll have another beer.

    M 1 Reply Last reply
    0
    • C CataclysmicQuantum

      You would get better information in the C++ forum since hooks deal with the windows api.

      Word, write letters and sh*t yo. It takes 46 muscles to frown but only 4 to flip 'em the bird. Friendship is like peeing on yourself: everyone can see it, but only you get the warm feeling that it brings. The greatest pleasure in life is doing what people say you cannot do. Everyone needs believe in something. I believe I'll have another beer.

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #4

      You suggest him to post the C# question in C++ forum? :doh:

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      A 1 Reply Last reply
      0
      • M Michael Sync

        You suggest him to post the C# question in C++ forum? :doh:

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        A Offline
        A Offline
        Anton Afanasyev
        wrote on last edited by
        #5

        I can understand him...C++ developers are _generally_ more knowledgeable about API's that C# devs. Which is why I really dont know where to put the question.

        M 1 Reply Last reply
        0
        • A Anton Afanasyev

          Where would I post a question about myself having a problem with keyboard hooking, using C#, running under Vista, and the whole thing not working when VMWare Workstation is the topmost window? Yes, I am serious. I really dont know which forum to post this to

          A Offline
          A Offline
          About
          wrote on last edited by
          #6

          using System; using System.Diagnostics; using System.Windows.Forms; using System.Runtime.InteropServices; class InterceptKeys { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private static LowLevelKeyboardProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; public static void Main() { _hookID = SetHook(_proc); Application.Run(); UnhookWindowsHookEx(_hookID); } private static IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private delegate IntPtr LowLevelKeyboardProc( int nCode, IntPtr wParam, IntPtr lParam); private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); Console.WriteLine((Keys)vkCode); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr GetModuleHandle(string lpModuleName); }

          union quest yLe read while is uniquestyLewww uniquestyLew_3_ b3nY@msn.com

          A 1 Reply Last reply
          0
          • A About

            using System; using System.Diagnostics; using System.Windows.Forms; using System.Runtime.InteropServices; class InterceptKeys { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private static LowLevelKeyboardProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; public static void Main() { _hookID = SetHook(_proc); Application.Run(); UnhookWindowsHookEx(_hookID); } private static IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private delegate IntPtr LowLevelKeyboardProc( int nCode, IntPtr wParam, IntPtr lParam); private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); Console.WriteLine((Keys)vkCode); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr GetModuleHandle(string lpModuleName); }

            union quest yLe read while is uniquestyLewww uniquestyLew_3_ b3nY@msn.com

            A Offline
            A Offline
            About
            wrote on last edited by
            #7

            class InterceptMouse { private static LowLevelMouseProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; public static void Main() { _hookID = SetHook(_proc); Application.Run(); UnhookWindowsHookEx(_hookID); } private static IntPtr SetHook(LowLevelMouseProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam); private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam) { MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } private const int WH_MOUSE_LL = 14; private enum MouseMessages { WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202, WM_MOUSEMOVE = 0x0200, WM_MOUSEWHEEL = 0x020A, WM_RBUTTONDOWN = 0x0204, WM_RBUTTONUP = 0x0205 } [StructLayout(LayoutKind.Sequential)] private struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] private struct MSLLHOOKSTRUCT { public POINT pt; public uint mouseData; public uint flags; public uint time; public IntPtr dwExtraInfo; } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern

            A 1 Reply Last reply
            0
            • A About

              class InterceptMouse { private static LowLevelMouseProc _proc = HookCallback; private static IntPtr _hookID = IntPtr.Zero; public static void Main() { _hookID = SetHook(_proc); Application.Run(); UnhookWindowsHookEx(_hookID); } private static IntPtr SetHook(LowLevelMouseProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam); private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam) { MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); Console.WriteLine(hookStruct.pt.x + ", " + hookStruct.pt.y); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } private const int WH_MOUSE_LL = 14; private enum MouseMessages { WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202, WM_MOUSEMOVE = 0x0200, WM_MOUSEWHEEL = 0x020A, WM_RBUTTONDOWN = 0x0204, WM_RBUTTONUP = 0x0205 } [StructLayout(LayoutKind.Sequential)] private struct POINT { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] private struct MSLLHOOKSTRUCT { public POINT pt; public uint mouseData; public uint flags; public uint time; public IntPtr dwExtraInfo; } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern

              A Offline
              A Offline
              Anton Afanasyev
              wrote on last edited by
              #8

              Well, while I _am_ thankful for the sample codes (or, rather, the mouse code, as my keyboard code is the same idea), it still has the same problem. The code works in _every_ window (except the elevated ones in vista, but that can be overcome by running the app elevated, so not a problem), except when a VMWare workstation is open in full screen. Then, the code does not receive any keyboard events. I've tried setting the timeout (Thread.Sleep) before the hook occurs, so that the hook happens after the VMWare window is maximized. Still, nothing. It's as if VMWare hooks the keyboard at a much lower level than the WH_KEYBOARD_LL allows. Perhaps it hooks IRQ interrupts? Any ideas?

              A 1 Reply Last reply
              0
              • A Anton Afanasyev

                I can understand him...C++ developers are _generally_ more knowledgeable about API's that C# devs. Which is why I really dont know where to put the question.

                M Offline
                M Offline
                Michael Sync
                wrote on last edited by
                #9

                Anton Afanasyev wrote:

                C++ developers are _generally_ more knowledgeable about API's that C# devs

                yeah. it's ture but C# developer might know about hooking too.. Anyway, C# question should go to C# forum only..

                Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

                1 Reply Last reply
                0
                • A Anton Afanasyev

                  Well, while I _am_ thankful for the sample codes (or, rather, the mouse code, as my keyboard code is the same idea), it still has the same problem. The code works in _every_ window (except the elevated ones in vista, but that can be overcome by running the app elevated, so not a problem), except when a VMWare workstation is open in full screen. Then, the code does not receive any keyboard events. I've tried setting the timeout (Thread.Sleep) before the hook occurs, so that the hook happens after the VMWare window is maximized. Still, nothing. It's as if VMWare hooks the keyboard at a much lower level than the WH_KEYBOARD_LL allows. Perhaps it hooks IRQ interrupts? Any ideas?

                  A Offline
                  A Offline
                  About
                  wrote on last edited by
                  #10

                  dwThreadId [in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread Well, I still I use XP, not yet vista.. and I can not write a lot in english but it may your help about link this: http://www.experts-exchange.com/Programming/Languages/CPP/Q_21262041.html?qid=21262041[^] http://www.codeguru.com/forum/showthread.php?t=389394[^] http://www.thescripts.com/forum/thread533002.html[^] It was my problem also while do the .NET framework update and update - Get UBUNTU - ;P

                  union quest yLe read while is uniquestyLewww uniquestyLew_3_ b3nY@msn.com

                  1 Reply Last reply
                  0
                  • A Anton Afanasyev

                    Where would I post a question about myself having a problem with keyboard hooking, using C#, running under Vista, and the whole thing not working when VMWare Workstation is the topmost window? Yes, I am serious. I really dont know which forum to post this to

                    J Offline
                    J Offline
                    Joan M
                    wrote on last edited by
                    #11

                    Could it be that VMWare is using hooks also and it is intercepting yours because they have more priority? Just a guess...

                    https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                    A 1 Reply Last reply
                    0
                    • J Joan M

                      Could it be that VMWare is using hooks also and it is intercepting yours because they have more priority? Just a guess...

                      A Offline
                      A Offline
                      Anton Afanasyev
                      wrote on last edited by
                      #12

                      This is exactly what I am thinking, but I've never delved deep enough into this to know much. What I do know, is that even if I apply my hook after VMWare window goes fullscreen (at least if I was VMWare, thats when I would hook the keyboard), mine still doesnt trigger. So I am thinking that it uses some sort of even lower-level hook. Like IRQ interrupts, perhaps? This is actually kinda funny. The reason I am doing the whole keyboard hooking thing is because my keyboard has those few extra keys (ie, play, stop, pause, etc), and I've had problems with the drivers for it in the past, so decided to either make my own (yeah, right. never tried, so maybe sometime in the future), or just simply hook the input, and then process the specific keys there. But since I spend quite a bit of time in a VMWare machine, the problem is very annoying.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups