找回密码
 加入
搜索
查看: 4773|回复: 3

[系统综合] 关于User32.dll里的GetKeyState和GetKeyboardState的函数调用问题【已解决】

[复制链接]
发表于 2011-4-22 16:26:39 | 显示全部楼层 |阅读模式
本帖最后由 editcue 于 2011-4-23 15:16 编辑

我想做一个实时显示当前按键状态的软件,就是监视键盘按键是否为按下状态。
希望能在在录制视频教程时,按下按键,在屏幕即时显示当前按键。
所以需要用到一个全局和hook。
我在MSDN找到了user32.dll,里面有这样的两个函数:
MSDN:GetKeyState
百度百科:GetKeyState
MSDN:GetKeyboardState
百度百科:GetKeyboardState
写了下面一段脚本:
$User32 = DllOpen("user32.dll")
$KeyState=DllCall($User32, "short", "GetKeyState", "long", 144) 
$KeyboardState=DllCall($User32,"long","GetKeyboardState","long",144)
MsgBox(0,"1",$KeyState,2)
WinWaitClose("1")
MsgBox(0,"1",$KeyboardState,2)
DllClose($User32)
问题:
为什么运行上面代码没有任何返回值呢?
试过Num Lock打开状态,没有任何返回值。后面的“虚拟键码参数”,试过“十进制”和“十六进制”的都不行。
到底是哪里出错呢?
发表于 2011-4-22 19:05:37 | 显示全部楼层
干么非要用dll  直接写个代码就是了
 楼主| 发表于 2011-4-22 19:42:04 | 显示全部楼层
干么非要用dll  直接写个代码就是了
haijie1223 发表于 2011-4-22 19:05



    说的是直接用UDF的_IsPressed函数吗?刚刚看了一下_IsPressed的源代码
Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
        ; $hexKey must be the value of one of the keys.
        ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
        Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
        If @error Then Return SetError(@error, @extended, False)
        Return BitAND($a_R[0], 0x8000) <> 0
EndFunc   ;==>_IsPressed
原来是用GetAsyncKeyState函数。。。汗啊。折腾了这么久,原来已经有Defined了。
谢谢啊。
发表于 2013-6-7 21:45:49 | 显示全部楼层
哇!~....真的是高手
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-29 03:20 , Processed in 0.083508 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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