1
我目前使用的是Visual Basic 2010:如何使用GetAsyncKeyState創建全局熱鍵?
我想用熱鍵創建一個自動打字機。這些熱鍵的目的即使在最小化時也是如此,所以當玩視頻遊戲或打字進入網站聊天時,我可以鍵入「F12」,它會發送我已經預設的任何消息,而不必取消最小化我的程序製作!
下面是我所擁有的,到目前爲止,我會很感激一些幫助。
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
你將需要考慮使用這樣的Windows API函數[SO問題](http://stackoverflow.com/questions/14168258/registering-3-hotkeys-possible/14168506#14168506)問或您需要使用像這樣的圖書館[GlobalMouseKeyboardHook](http://globalmousekeyhook.codeplex.com/) –