注册
 找回密码
 注册
江西广告网
查看: 310|回复: 0
打印 上一主题 下一主题

如何识别键盘左右的shift,Ctrl或Alt键

[复制链接]

该用户从未签到

1
跳转到指定楼层
发表于 2008-12-24 11:59:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x
  用API (GetAsyncKeyState)实现,在WIN 2K,XP 下有效:      Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer   Private Const VK_LSHIFT = &HA0   Private Const VK_RSHIFT = &HA1   Private Const VK_LCTRL = &HA2   Private Const VK_RCTRL = &HA3   Private Const VK_LMENU = &HA4   Private Const VK_RMENU = &HA5      Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)   If KeyCode = vbKeyShift And Shift = vbShiftMask And (GetAsyncKeyState(VK_LSHIFT) And &H8000)    Then MsgBox "you click the Left Shift"   If KeyCode = vbKeyShift And Shift = vbShiftMask And (GetAsyncKeyState(VK_RSHIFT) And &H8000)   Then MsgBox "you click the RIGHT Shift"      If KeyCode = vbKeyMenu And Shift = vbAltMask And (GetAsyncKeyState(VK_LMENU) And &H8000)   Then MsgBox "you click the Left ALT" ' only ALT was pressed   If KeyCode = vbKeyMenu And Shift = vbAltMask And (GetAsyncKeyState(VK_RMENU) And &H8000)   Then MsgBox "you click the RIGHT ALT" ' only ALT was pressed      If KeyCode = vbKeyControl And Shift = vbCtrlMask And (GetAsyncKeyState(VK_LCTRL) And &H8000)    Then MsgBox "you click the Left CTRL"   If KeyCode = vbKeyControl And Shift = vbCtrlMask And (GetAsyncKeyState(VK_RCTRL) And &H8000)   Then MsgBox "you click the Right CTRL"      End Sub      Private Sub Form_Load()   Me.KeyPreview = True   End Sub       <
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表