Share via

How can I make a key spammer for a specific software on vb.net

Frequency 1 Reputation point
2021-06-14T18:45:55.693+00:00

Hi,

I have managed to make my software to spam a certain letter or number, but i want it to target a specific window that is open which then it will allow me to utilise both of my monitors.

i am using vb.net

Developer technologies | VB

4 answers

Sort by: Most helpful
  1. Castorix31 91,851 Reputation points
    2021-06-15T21:22:08+00:00

    You must activate and set focus to the destination window.
    For example, with Notepad =>

            Dim hWnd As IntPtr = FindWindow("Notepad", Nothing)
            If (hWnd <> IntPtr.Zero) Then
                SwitchToThisWindow(hWnd, 1)
                SendKeys.Send("x")
            End If
    

    Declarations :

    <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Public Shared Function SwitchToThisWindow(hWnd As IntPtr, fAltTab As Boolean) As Boolean
    End Function
    
    <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function
    
    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Castorix31 91,851 Reputation points
    2021-06-23T06:27:35.56+00:00

    im trying to spam the notepad while being able to browse my PC do you get me?

    You can use PostMessage, but it is not recommended...

    Same test with Notepad =>

    Dim hWndTarget As IntPtr = FindWindow("Notepad", Nothing)
    If (hWndTarget <> IntPtr.Zero) Then
        ' Get Edit control handle
        hWndTarget = GetWindow(hWndTarget, GW_CHILD)
        PostMessage(hWndTarget, WM_KEYDOWN, Keys.X, IntPtr.Zero)
    End If
    

    Declarations :

        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal msg As UInteger, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
    
        Public Const WM_KEYDOWN = &H100
        Public Const WM_KEYUP = &H101
    
        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
        Public Shared Function GetWindow(hWnd As IntPtr, uCmd As UInteger) As IntPtr
        End Function
    
        Public Const GW_HWNDFIRST = 0
        Public Const GW_HWNDLAST = 1
        Public Const GW_HWNDNEXT = 2
        Public Const GW_HWNDPREV = 3
        Public Const GW_OWNER = 4
        Public Const GW_CHILD = 5
    

  4. Frequency 1 Reputation point
    2021-06-22T17:26:27.977+00:00

    can anyone help me with this please

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.