1

I'm currently using Visual Basic 2010:

I would like to create an Auto Typer with Hot Keys. The purpose for these hot keys would be even when minimized, so when playing a video game or typing into a website chat I may type "F12" and it will send whatever message I have preset without having to un-minimize the program I've made!

Below is what I have got so far, I'd appreciate some help.

Public Class Form1
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) _
                                                                        As Short
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If GetAsyncKeyState(Keys.F12) Then Button1.PerformClick()
        SendKeys.Send(TextBox1.Text)
        SendKeys.Send("{Enter}")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("The message box was left blank!", MsgBoxStyle.Exclamation)
            Timer1.Stop()
        Else
            Timer1.Interval = TextBox2.Text * 1000
            Timer1.Start()
            Me.WindowState = FormWindowState.Minimized
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub
End Class
Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Dylberts
  • 11
  • 1
  • You are going to need to look into using Windows API functions like this [SO Question](http://stackoverflow.com/questions/14168258/registering-3-hotkeys-possible/14168506#14168506) is asking or you need to use a Library like this [GlobalMouseKeyboardHook](http://globalmousekeyhook.codeplex.com/) – Mark Hall Dec 15 '13 at 03:08

1 Answers1

0

Add another timer (timer2) to check if F12 key pressed or not and if it pressed timer1 will start and check for the any text it the textbox1 in timer1 not when your press the button thats if you will continue including Button1.PerformClick() Or you will need to move the text sending code to button but i recommend to add another timer

thats the code for the 2 timers ,, (set the enable option to true on form load event or from the visual studio)

Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Int32)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If GetAsyncKeyState(Keys.F12) Then
        Timer2.Start()
    End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    If TextBox1.Text <> "" Then
        SendKeys.Send(TextBox1.Text)
        SendKeys.Send("{Enter}")
    Else
        MsgBox("Error", MsgBoxStyle.Exclamation)
        Timer1.Stop()
    End If
End Sub
End Class