VB类模块Event事件代码在什么地方编写5249
1个回答
2013-11-17
展开全部
是类模块还是标准模块,方法不一样的, 标准模块这样写
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Const VK_X = &H58
Private Sub Timer1_Timer()
keybd_event VK_X, 0, 0, 0 '按下X
keybd_event VK_X, 0, KEYEVENTF_KEYUP, 0 '松开X
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 Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'以上是声明
Public Function 按键按下(按键码 As Byte)
按键按下 = keybd_event(按键码, 0, 0, 0)
End Function
Public Function 按键松开(按键码 As Byte)
按键松开 = keybd_event(按键码, 0, KEYEVENTF_KEYUP, 0)
End Function
然后就是调用了,在标准模块这样写:
很简化。还有不明白的来问我。
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Const VK_X = &H58
Private Sub Timer1_Timer()
keybd_event VK_X, 0, 0, 0 '按下X
keybd_event VK_X, 0, KEYEVENTF_KEYUP, 0 '松开X
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 Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'以上是声明
Public Function 按键按下(按键码 As Byte)
按键按下 = keybd_event(按键码, 0, 0, 0)
End Function
Public Function 按键松开(按键码 As Byte)
按键松开 = keybd_event(按键码, 0, KEYEVENTF_KEYUP, 0)
End Function
然后就是调用了,在标准模块这样写:
很简化。还有不明白的来问我。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询