|
本帖最后由 dddfr 于 2019-6-12 07:10 编辑
看到坛里有很多网友需要使用KeyUp事件,以前只能用控件来实现,功能上很受限制。本次利用SubClass制作了COM组件,实现KeyUp事件。类名为KeyUpEvent,实现两个方法,其中init为初始化,传入需要监测按键的窗口;terminate为终止,参数与init相同。
Class: KeyUpEvent
Method:
init(wn as Window)
Terminate(wn as Window)
Event:KeyUp(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long)
Excel示例代码如下:
Dim WithEvents keyup As KeyUpEvent
Sub start()
Set keyup = New KeyUpEvent
keyup.Init ActiveWindow
End Sub
Sub terminate()
keyup.terminate ActiveWindow
End Sub
Private Sub keyup_KeyUp(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long)
MsgBox wParam
End Sub
注意本代码只能写在对象里,即worksheet或thisworkbook里,不能写在模块里,获取的键限于功能按键,数字键和字母键的组件稍晚发布
|
评分
-
2
查看全部评分
-
|