Option ExplicitPrivate Const VK_LBUTTON = &H1Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_KeyPress(KeyAscii As Integer)
If GetAsyncKeyState(vbKeyF11) <> 0 Then
MsgBox "你按了F11!"
End If
If GetAsyncKeyState(VK_LBUTTON) <> 0 Then
MsgBox "你按了左键!"
End If
If GetAsyncKeyState(vbKeyA) <> 0 Then
MsgBox "你按了a!"
End If
If GetAsyncKeyState(vbKeyB) <> 0 Then
MsgBox "你按了b!"
End If
End Sub
1\为什么单击左键和按F11键不立即响应,而按a和b键却会响应?2\能实现按了左键和F11键立即响应的代码吗
Private Sub Form_KeyPress(KeyAscii As Integer)
If GetAsyncKeyState(vbKeyF11) <> 0 Then
MsgBox "你按了F11!"
End If
If GetAsyncKeyState(VK_LBUTTON) <> 0 Then
MsgBox "你按了左键!"
End If
If GetAsyncKeyState(vbKeyA) <> 0 Then
MsgBox "你按了a!"
End If
If GetAsyncKeyState(vbKeyB) <> 0 Then
MsgBox "你按了b!"
End If
End Sub
1\为什么单击左键和按F11键不立即响应,而按a和b键却会响应?2\能实现按了左键和F11键立即响应的代码吗
解决方案 »
- VB中如何用API函数自绘控件,,,比如按钮、窗体......
- 我按F9建窗体实现了隐藏,代码是“If KeyCode = 120 Then yhe.Show '按F9建”,但如何写代码将窗体重现呢?下列代码按F10键不能实现:If KeyCode = 121 Then yhe.Hide 'F10。谁有办法解决?
- *-* 我的一段代码怎么调试不对啊,谁帮忙看看啊 。。在Form_Load 过程中怎么向组合列表框中添加列表项,可以供用户选择啊?? 急死了!
- 出错
- VB如调用API复制文件,并可以判断文件已经复制成功!
- 交换友情链接
- 谁能提供 CRYSTAL REPORT的连接字符串例子
- 如何使用Setup Factory对打包的程序中调用的注册
- 求教高手
- 如何让我的程序在启动之后自动最小化
- 如何判断程序运行在F5调试环境下?条件编译??
- 如何访问web网页并向其传参数,并执行其中的代码?
键盘左键是 vbKeyLeft把代码放在计时器中:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF11) <> 0 Then
MsgBox "你按了F11!"
End If
If GetAsyncKeyState(vbKeyLeft) <> 0 Then
MsgBox "你按了左键!"
End If
If GetAsyncKeyState(vbKeyA) <> 0 Then
MsgBox "你按了a!"
End If
If GetAsyncKeyState(vbKeyB) <> 0 Then
MsgBox "你按了b!"
End If
End Sub