思路:通过Key_Press事件捕获键盘输入,如果键盘输入的是空格,则调用按钮命令
步骤如下:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then'空格键的ASCII码为32
call Command1_click '调用命令
end if
End Sub
添加以下代码到窗体中
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then Command1 = True
End Sub
其中32就是空格对应的Ascii码。Command1就是空格要控制的按钮名称,根据实际情况修改吧。
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then Call Command1_Click
End Sub