程序包含一个标签和一个间隔1秒的时间控件
Private xx(1 To 5) As String
Private i As Integer, f As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 112 Then
f = MsgBox("你按了F1,继续吗?", vbYesNo + vbInformation, "提示")
If f = vbYes Then
Timer1Enabled = True
Else
Call Form_KeyDown(113, 0)
End If
ElseIf KeyCode = 113 Then
MsgBox "你按了F2键,结束应用程序!"
End
End If
End Sub
Private Sub Form_Load()
xx(1) = "aaaaaaaaaa"
xx(2) = "bbbbbbbbbb"
xx(3) = "cccccccccc"
xx(4) = "dddddddddd"
xx(5) = "请按F1、F2"
i = 1
End Sub
Private Sub Timer1_Timer()
Label1Caption = xx(i)
If xx(i) = "请按F1、F2" Then
Timer1Enabled = False
Call Form_KeyDown(112, 0)
End If
i = i + 1
If i > 5 Then i = 1
End Sub
你也可以手动按F1、F2 效果一样!
Dim a(1 To 100) As String
Dim i As Integer, x As Integer
Const n = 3 'n的值可根据实际需要赋予不同的变量
Private Sub Command1_Click()
Timer1Enabled = True
End Sub
Private Sub Command2_Click()
Timer1Enabled = False
End Sub
Private Sub Form_Load()
Randomize '初始化随机数生成器
a(1) = "富士康" '以此将n个人的姓名保存在数组a中
a(2) = "庞麦郎"
a(3) = "非主流"
For i = 1 To n
List1AddItem a(i)
Next
Timer1Enabled = False
End Sub
Private Sub Timer1_Timer()
x = Rnd() n + 1 '产生一个[1,n]中的随机整数并存入变量x中
Label2Caption = a(x) '在标签Label2中显示下标变量a(x)的值(第x个人的姓名)
End Sub
双色球随机选:
Private Sub Command1_Click()
Dim a(6) As Integer
Dim b As Integer
For i = 1 To 6
a(i) = Int(Rnd() (1 + (33 - 1))) + 1
For j = 1 To i - 1
If a(i) = a(j) Then
i = i - 1
End If
Next
Next
For i = 1 To 6
For j = i + 1 To 6
If a(i) < a(j) Then
T = a(i): a(i) = a(j): a(j) = T
End If
Next
Next
b = Int(Rnd() (1 + (16 - 1))) + 1
Text1Text = a(6) & " " & a(5) & " " & a(4) _
& " " & a(3) & " " & a(2) & " " & a(1) & " +" & b
End Sub
'一个Timer : Timer1
'两个Command : Command1,Command2
'三个OptionBox : Option1 , Option2 , Option3
Option Explicit
'
'请把详细过程和代码说下
Private Sub Command1_Click()
'1:按键盘的 ALT+TAB(是先按ALT然后不松开ALT按TAB 目的就是为了切换)
SendKeys "%{TAB}"
MeTimer1Enabled = True
End Sub
Private Sub Command2_Click()
MeTimer1Enabled = False
End Sub
Private Sub Form_Load()
MeTimer1Interval = 1000
MeTimer1Enabled = False
End Sub
Private Sub Timer1_Timer()
'前面有6个选择。后面是6个相对应的运行按键 然后还有一个停止按键,按后停止所有动作。
'
'例如选择1(在1选择那打勾,然后点运行后 键盘自动先按ctrl+d后按ctrl+q
If MeOption1Value Then
SendKeys "^D"
SendKeys "^Q"
End If
'选择2(在2选择那打勾,然后点运行后 键盘自动先按ctrl+d后按ctrl+d
'
If MeOption2Value Then
SendKeys "^D"
SendKeys "^D"
End If
'选择3(在3选择那打勾,然后点运行后 键盘自动先按ctrl+q后按ctrl+q
If MeOption2Value Then
SendKeys "^Q"
SendKeys "^Q"
End If
'选择3(在3选择那打勾,然后点运行后 键盘自动先按ctrl+q后按ctrl+a
'
If MeOption3Value Then
SendKeys "^Q"
SendKeys "^A"
End If
'
'
'忘了 都要是 能无限 按的 直到自己按 停止 键后才停止!
End Sub
写了一个简易代码,基本上能满足你的需求~~
在Form上添加两个Timer控件,然后在代码窗口中复制粘贴以下代码:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Sub Form_Load()
Timer1Interval = 100
Timer2Interval = 500
Timer1Enabled = 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 Timer1Enabled = False Then
Timer1Enabled = True
Else
Timer1Enabled = False
End If
End If
End Sub
程序运行后,按下键盘字符6键后开始不停按键 *** 作,再次按下字符6键即停止。这段代码只适用于目标程序处于前台窗口激活状态下使用!
以上就是关于请教用VB编写一个自动按键小程序全部的内容,包括:请教用VB编写一个自动按键小程序、VB中可用的抽奖程序的代码、如何用VB编写一个简单的选号器就是点击然后程序随机帮选出一个数(1~70个数)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)