怎样用VB间隔几秒按下一个键???
PrivateSubTimer1_Timer()Callkeybd_event(82,0,0,0)'模拟按下"R"键EndSub这里只可以按下一个键!!我想用一个多选列表...
Private Sub Timer1_Timer()
Call keybd_event(82, 0, 0, 0) '模拟按下"R"键
End Sub
这里只可以按下一个键!!我想用一个多选列表来实现可选按键!!
我是一个VB新手,可不可以详解一下?谢谢!!
要用控件Check,Textbox,ComBox,Timer组成!
1,由Textbox来设定Timer的Interval !
2,由ComBox来选定所要的按键(要是ascii码的那种,而在ComBox里显示ascii码所对应的键名) 展开
Call keybd_event(82, 0, 0, 0) '模拟按下"R"键
End Sub
这里只可以按下一个键!!我想用一个多选列表来实现可选按键!!
我是一个VB新手,可不可以详解一下?谢谢!!
要用控件Check,Textbox,ComBox,Timer组成!
1,由Textbox来设定Timer的Interval !
2,由ComBox来选定所要的按键(要是ascii码的那种,而在ComBox里显示ascii码所对应的键名) 展开
6个回答
展开全部
在Form1中添加四个控件:timer控件,combo控件(下拉式列表),两个button控件.只需将以下代码拷过去就能实现楼主的功能啦!
Private Sub Command1_Click()
'设定时间间隔为1秒
Timer1.Interval = 1000
End Sub
Private Sub Command2_Click()
Timer1.Interval = 0
End Sub
Private Sub Form_Load()
Dim str As Variant
Dim i As Integer
'初始化一些数据
Combo1.Text = "请选择您要模拟的按键名称"
Command1.Caption = "开始模拟按键"
Command2.Caption = "停止模拟按键"
'把你想要模拟的按键全部添加到以下这个数组中
str = Array("A", "B", "C", "D", "E", "F", "G", "H", "i", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
For i = 0 To 25
Combo1.AddItem str(i)
Next
End Sub
Private Sub Timer1_Timer()
SendKeys Combo1.Text
End Sub
Private Sub Command1_Click()
'设定时间间隔为1秒
Timer1.Interval = 1000
End Sub
Private Sub Command2_Click()
Timer1.Interval = 0
End Sub
Private Sub Form_Load()
Dim str As Variant
Dim i As Integer
'初始化一些数据
Combo1.Text = "请选择您要模拟的按键名称"
Command1.Caption = "开始模拟按键"
Command2.Caption = "停止模拟按键"
'把你想要模拟的按键全部添加到以下这个数组中
str = Array("A", "B", "C", "D", "E", "F", "G", "H", "i", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
For i = 0 To 25
Combo1.AddItem str(i)
Next
End Sub
Private Sub Timer1_Timer()
SendKeys Combo1.Text
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'你这样按键不太正确,应添加按下及松开两个动作。
'所以声明部分应加上以下函数,然后复制代码部分就可以了。
'用法是:你在combox中选择一个按键,马上就会有按键动作。
'====声明部分====
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'====代码部分====
Private Sub Timer1_Timer()
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY, 0 '按下键
Sleep 100
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 '松开键
End Sub
'所以声明部分应加上以下函数,然后复制代码部分就可以了。
'用法是:你在combox中选择一个按键,马上就会有按键动作。
'====声明部分====
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'====代码部分====
Private Sub Timer1_Timer()
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY, 0 '按下键
Sleep 100
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 '松开键
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'====代码部分====
Private Sub Timer1_Timer()
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY, 0 '按下键
Sleep 100
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 '松开键
End Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'====代码部分====
Private Sub Timer1_Timer()
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY, 0 '按下键
Sleep 100
keybd_event Val(combo1.list(combox1.listindex)), 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0 '松开键
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command2_Click()
Combo1.Clear
Combo1.AddItem "ab"
Combo1.AddItem "1bzwer5"
End Sub
Private Sub Timer1_Timer()
Static i
If Combo1.Text = "" Then Exit Sub
i = (i Mod Len(Combo1.Text)) + 1
Call keybd_event(Asc(UCase(Mid(Combo1.Text, i, 1))), 0, 0, 0)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 5000
End Sub
Private Sub Command2_Click()
Combo1.Clear
Combo1.AddItem "ab"
Combo1.AddItem "1bzwer5"
End Sub
Private Sub Timer1_Timer()
Static i
If Combo1.Text = "" Then Exit Sub
i = (i Mod Len(Combo1.Text)) + 1
Call keybd_event(Asc(UCase(Mid(Combo1.Text, i, 1))), 0, 0, 0)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 5000
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在窗体上放一个TIMER控件 然后在timer控件里面写sendkeys("你要按下的建名")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询