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. General Programming
  3. Visual Basic
  4. keyboard hooking in VB.net

keyboard hooking in VB.net

Scheduled Pinned Locked Moved Visual Basic
csharphtmlcomjson
5 Posts 3 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.
  • M Offline
    M Offline
    matthew kelly
    wrote on last edited by
    #1

    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

    D M 2 Replies Last reply
    0
    • M matthew kelly

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      What would you like to know? RageInTheMachine9532

      M 1 Reply Last reply
      0
      • M matthew kelly

        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

        M Offline
        M Offline
        Matthew Hazlett
        wrote on last edited by
        #3

        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.KeyDown

        Select Case e.KeyData
        Case Keys.End
        ...
        case Keys.Subtract Or Keys.Shift ' this is the _ key (Kinda confusing)
        ...
        end select
        end sub

        Just make sure to use Keys.??? or Keys.Shift if its a shifted key.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          What would you like to know? RageInTheMachine9532

          M Offline
          M Offline
          matthew kelly
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • M matthew kelly

            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

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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 Function

            Well, 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

            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