當前位置:編程學習大全網 - 網站源碼 - VB 怎麽做 自動按鍵

VB 怎麽做 自動按鍵

寫了壹個簡易代碼,基本上能滿足妳的需求~~

在Form上添加兩個Timer控件,然後在代碼窗口中復制粘貼以下代碼:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

Private Sub Form_Load()

Timer1.Interval = 100

Timer2.Interval = 500

Timer1.Enabled = False

End Sub

Private Function MyHotKey(vKeyCode) As Boolean

MyHotKey = GetAsyncKeyState(vKeyCode) < 0

End Function

Private Sub Timer1_Timer()

SendKeys "{5}"

SendKeys "{3}"

SendKeys "{2}"

SendKeys "{4}"

SendKeys "{7}"

SendKeys "{8}"

SendKeys "{9}"

End Sub

Private Sub Timer2_Timer()

If MyHotKey(vbKey6) Then

If Timer1.Enabled = False Then

Timer1.Enabled = True

Else

Timer1.Enabled = False

End If

End If

End Sub

程序運行後,按下鍵盤字符6鍵後開始不停按鍵操作,再次按下字符6鍵即停止。這段代碼只適用於目標程序處於前臺窗口激活狀態下使用!

  • 上一篇:安裝E-computing插件時,如何查看所有已安裝的CAD?
  • 下一篇:景豐mx3怎麽調整音量大小
  • copyright 2024編程學習大全網