keyboard hooking in VB.net
-
I have found these (2) articles on keyboard hooking by Paul Kimmel @ codeguru.com and am looking for discussion threads that might have occured around them. I am looking for an vb.net projec examples that use the module. Managing Low-level Keyboard Hooks in VB .NET Dated April 18, 2003 http://www.codeguru.com/vb\_system/PK041803.html Managing Low-Level Keyboard Hooks with the Windows API Dated November 18, 2002 http://www.codeguru.com/vb\_system/PK111802.html I would think that there would be a discussion thread about the articles at this site, but I can't seem to find it. Thank you for your time and attention. Sincerely, Matthew Kelly vb.net programmer newbe
-
I have found these (2) articles on keyboard hooking by Paul Kimmel @ codeguru.com and am looking for discussion threads that might have occured around them. I am looking for an vb.net projec examples that use the module. Managing Low-level Keyboard Hooks in VB .NET Dated April 18, 2003 http://www.codeguru.com/vb\_system/PK041803.html Managing Low-Level Keyboard Hooks with the Windows API Dated November 18, 2002 http://www.codeguru.com/vb\_system/PK111802.html I would think that there would be a discussion thread about the articles at this site, but I can't seem to find it. Thank you for your time and attention. Sincerely, Matthew Kelly vb.net programmer newbe
What would you like to know? RageInTheMachine9532
-
I have found these (2) articles on keyboard hooking by Paul Kimmel @ codeguru.com and am looking for discussion threads that might have occured around them. I am looking for an vb.net projec examples that use the module. Managing Low-level Keyboard Hooks in VB .NET Dated April 18, 2003 http://www.codeguru.com/vb\_system/PK041803.html Managing Low-Level Keyboard Hooks with the Windows API Dated November 18, 2002 http://www.codeguru.com/vb\_system/PK111802.html I would think that there would be a discussion thread about the articles at this site, but I can't seem to find it. Thank you for your time and attention. Sincerely, Matthew Kelly vb.net programmer newbe
VS.NET already has lots of keyboard stuff in it. But be carefull I spent lotsa time trying to get shifted keys to work.
Private Sub Edit_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles Edit.KeyDownSelect Case e.KeyData
Case Keys.End
...
case Keys.Subtract Or Keys.Shift ' this is the _ key (Kinda confusing)
...
end select
end subJust make sure to use
Keys.??? or Keys.Shift
if its a shifted key. -
What would you like to know? RageInTheMachine9532
I am currently using the vb.net module included in the above article. The code works really well. I am trying to add to this project a new class “CurrentWindowWithKeyboardFocus” , which will include variables and functions that will determine Handle to window with keyboard focus window x position window y position window width window height What I am confused about is how I can get the handle of the window that has the keyboard focus. Is it a handle to a process?? I have attached a preliminary copy of my new class. I am looking for recommendations?? Should the class inherit from "System.Windows.Forms.Control"?? Thanks for your time and attention. Public Class CurrentWindowWithKeyboardFocus Inherits System.Windows.Forms.Control Public CurrentWindow As Control Private CWXPosition As Integer Private CWYPosition As Integer Private CWWidth As Integer Private CWHeight As Integer Private CWHandle As IntPtr Public Sub New() 'gets the handle to the window CWHandle = HandleOfCurrentWindow() 'gets the x postion of the window CWXPosition = XPositionOfCurrentWindow(CWHandle) 'gets the y position of the window CWYPosition = YPositionOfCurrentWindow(CWHandle) 'gets the width of the window CWWidth = WidthOfCurrentWindow(CWHandle) 'gets the height of the window CWHeight = HeightOfCurrentWindow(CWHandle) End Sub Public Function HandleOfCurrentWindow() Dim WindowHandle As Integer Dim p As Process p = Process.GetCurrentProcess WindowHandle = Process.GetCurrentProcess.Handle.ToInt32 'get handle of current window 'return handle Return WindowHandle End Function Public Function XPositionOfCurrentWindow(ByRef intptr) Dim xpos 'get x position of current window 'return integer Return xpos End Function Public Function YPositionOfCurrentWindow(ByRef intptr) Dim Ypos 'get y position of current window 'return integer Return Ypos End Function Public Function WidthOfCurrentWindow(ByRef intptr) Dim Width 'get width of current window 'return integer Return Width End Function Public Function HeightOfCurrentWindow(ByRef intptr) Dim Height 'get width of current window 'return integer Return Height
-
I am currently using the vb.net module included in the above article. The code works really well. I am trying to add to this project a new class “CurrentWindowWithKeyboardFocus” , which will include variables and functions that will determine Handle to window with keyboard focus window x position window y position window width window height What I am confused about is how I can get the handle of the window that has the keyboard focus. Is it a handle to a process?? I have attached a preliminary copy of my new class. I am looking for recommendations?? Should the class inherit from "System.Windows.Forms.Control"?? Thanks for your time and attention. Public Class CurrentWindowWithKeyboardFocus Inherits System.Windows.Forms.Control Public CurrentWindow As Control Private CWXPosition As Integer Private CWYPosition As Integer Private CWWidth As Integer Private CWHeight As Integer Private CWHandle As IntPtr Public Sub New() 'gets the handle to the window CWHandle = HandleOfCurrentWindow() 'gets the x postion of the window CWXPosition = XPositionOfCurrentWindow(CWHandle) 'gets the y position of the window CWYPosition = YPositionOfCurrentWindow(CWHandle) 'gets the width of the window CWWidth = WidthOfCurrentWindow(CWHandle) 'gets the height of the window CWHeight = HeightOfCurrentWindow(CWHandle) End Sub Public Function HandleOfCurrentWindow() Dim WindowHandle As Integer Dim p As Process p = Process.GetCurrentProcess WindowHandle = Process.GetCurrentProcess.Handle.ToInt32 'get handle of current window 'return handle Return WindowHandle End Function Public Function XPositionOfCurrentWindow(ByRef intptr) Dim xpos 'get x position of current window 'return integer Return xpos End Function Public Function YPositionOfCurrentWindow(ByRef intptr) Dim Ypos 'get y position of current window 'return integer Return Ypos End Function Public Function WidthOfCurrentWindow(ByRef intptr) Dim Width 'get width of current window 'return integer Return Width End Function Public Function HeightOfCurrentWindow(ByRef intptr) Dim Height 'get width of current window 'return integer Return Height
matthew kelly wrote:
Public Function HandleOfCurrentWindow()
Dim WindowHandle As Integer
Dim p As Process
p = Process.GetCurrentProcess
WindowHandle = Process.GetCurrentProcess.Handle.ToInt32
'get handle of current window
'return handle
Return WindowHandle
End FunctionWell, first of all, your not getting the Window handle of the CurrentProcess. Your actually returning the handle to the Process itself, not it's Window. You have to use the MainWindowHandle propery of the process:
Dim WindowHandle as IntPtr
p = Process.GetCurrentProcess
WindowHandle = Process.GetCurrentProcess.MainWindowHandle()Now, after you get that, you can't use it in .NET to get the parameters of the window you want. .NET doesn't expose such functionality. But! You can use that window handle to get the parameters using the Win32 API. But! Some of the values you get back will probably surprise you! Send me an email address to send you the sample I wrote. It's a little too big to post here! All you have to do is click on other windows, like the VS IDE to see some interesting Normal Position values. Try it with an IE window too. RageInTheMachine9532