Since I dont know which board to post a question in, I'll ask where to post it...
-
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
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.
-
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.
You suggest him to post the C# question in C++ forum? :doh:
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
You suggest him to post the C# question in C++ forum? :doh:
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
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.
-
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
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
-
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
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
-
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
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?
-
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.
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)
-
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?
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
-
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
-
Could it be that VMWare is using hooks also and it is intercepting yours because they have more priority? Just a guess...
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.