Private Sub Form_KeyPress(KeyAscii As Integer) KeyAscii = 0 End Sub Private Sub Form_Load() Form1.KeyPreview = True End Sub全部键盘按键都无效了
你要留有用按键的话就这样Private Sub Form_Load() Form1.KeyPreview = True End Sub Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii <> 97 Then KeyAscii = 0 End If End Sub这样就只有A键才有效了 其他的都无效 根据你的情况自己改下吧
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) if shift<>3 and keycode<>80 then shift=0 keycode=0 end if End Sub Private Sub Form_Load() Form1.KeyPreview = True End Sub 你要什么全局么就所有窗体都写下这个代码,不要说你有n个窗体
Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub Form_Load()
Form1.KeyPreview = True
End Sub全部键盘按键都无效了
Form1.KeyPreview = True
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii <> 97 Then
KeyAscii = 0
End If
End Sub这样就只有A键才有效了
其他的都无效
根据你的情况自己改下吧
if shift<>3 and keycode<>80 then
shift=0
keycode=0
end if
End Sub
Private Sub Form_Load()
Form1.KeyPreview = True
End Sub
你要什么全局么就所有窗体都写下这个代码,不要说你有n个窗体
如果只是本窗体的话,上面有几位的代码就可以的了如果是全局,上面的就不行的了,因为上面的代码只是从本进程窗口消息队列中取的,对全局毫无意义一种简单的方法就是用全局KEYBAOARD HOOK,
还有DIRECT INPUT也可以,
不知道你要的性能怎么样,要求高的话写个filter也可以
给你个我以前写的c++例子HHOOK hhook;
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);//SetWindowsHookEx最后一参数可以选择本线程还是全局
hhook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, hInstance, 0) ;LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
if (pkbhs->vkCode == VK_A)
{ }
.....
}UnhookWindowsHookEx(hhook) ;