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

wangh2122 2004-07-24 10:59:24
我这个API也不行……
Declare GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long

但是有些软件确实能够区分开左边和右边的shift,Ctrl,Alt等键,请教下这是怎么做到的呢?
...全文
225 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueBeer 2004-07-30
  • 打赏
  • 举报
回复
好像都不灵啊,是不是GetAsyncKeyState不支持win98?
northwolves 2004-07-30
  • 打赏
  • 举报
回复
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer


32位下运行,在WIN 2K,XP 下有效。
helanshan 2004-07-30
  • 打赏
  • 举报
回复

VB声明
Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
说明
在给出扫描码的前提下,判断键名
返回值
Long,lpBuffer中载入的键名的实际长度
参数表
参数 类型及说明
lParam Long,位0到5=0;位16到23=按键的扫描码;位24=增强型键盘上的扩展位: 位25=如设为1,表示忽略左右Shift和Ctrl键的区别
lpBuffer String,字串预先初始化成至少nSize+1字节,以便随同键名载入
nSize Long,字串的最大长度

northwolves 2004-07-29
  • 打赏
  • 举报
回复
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
林选臣 2004-07-29
  • 打赏
  • 举报
回复
用DirectInput吧
dongge2000 2004-07-24
  • 打赏
  • 举报
回复
见过,不过那时我还没那个程度看不懂。
dongge2000 2004-07-24
  • 打赏
  • 举报
回复
UP
hhjjhjhj 2004-07-24
  • 打赏
  • 举报
回复
这个可以
Declare Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer

这里有个实例
http://office.9zp.com/dispbbs.asp?boardID=18&ID=1800
yinweihong 2004-07-24
  • 打赏
  • 举报
回复
UP
不会!~

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧