Imports System.Runtime.InteropServices Public Class Form1 Private Const WH_KEYBOARD_LL As Integer = 13 Private Const WM_KEYUP As Integer = &H101 Private Const WM_SYSKEYUP As Integer = &H105 Private proc As LowLevelKeyboardProcDelegate = AddressOf HookCallback Private hookID As IntPtr Private Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr <DllImport("user32")> Private Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr End Function <DllImport("user32.dll")> Private Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean End Function <DllImport("user32.dll")> Private Shared Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End Function <DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> Private Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr End Function Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. hookID = SetHook(proc) End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing UnhookWindowsHookEx(hookID) End Sub Private Function SetHook(ByVal proc As LowLevelKeyboardProcDelegate) As IntPtr Using curProcess As Process = Process.GetCurrentProcess() Using curModule As ProcessModule = curProcess.MainModule Return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0) End Using End Using End Function Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr ' we check keyup for standard printscreen, and syskeyup incase it is alt+printscreen ' we aren't checking keydown, as that fires before the screenshot is taken. If nCode >= 0 AndAlso (wParam.ToInt32 = WM_KEYUP OrElse wParam.ToInt32 = WM_SYSKEYUP) Then Dim vkCode As Integer = Marshal.ReadInt32(lParam) If vkCode = Keys.F6 Then Button1_Click(Me, EventArgs.Empty) End If End If Return CallNextHookEx(hookID, nCode, wParam, lParam) End Function Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim randy As Integer = CInt(Math.Ceiling(Rnd() * 100)) + 1 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 Button1.Text = "Start (F6)" Then Timer1.Interval = TextBox2.Text * 1000 Timer2.Interval = TextBox2.Text * 1000 If Me.Text = "TwonkTyper" Then Timer1.Start() Else Timer2.Start() End If Button1.Text = "Stop (F6)" Else Timer1.Stop() Timer2.Stop() Button1.Text = "Start (F6)" End If End Sub Declare Function apimouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer) Public Const MOUSEEVENTF_LEFTDOWN = &H2 Public Const MOUSEEVENTF_LEFTUP = &H4 Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.KeyPreview = True TextBox1.BackColor = Color.White TextBox2.BackColor = Color.White End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If Button2.Text = "Switch to AutoClicker" Then Button2.Text = "Switch to AutoTyper" Me.Text = "TwonkClicker" TextBox1.Enabled = False Label1.Enabled = False Else Button2.Text = "Switch to AutoClicker" Me.Text = "TwonkTyper" TextBox1.Enabled = True Label1.Enabled = True End If End Sub End Class
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub