【已解决】大神们:求助,请问autoit可以实现监控键盘状态吗?
本帖最后由 梦想 于 2017-8-31 09:51 编辑请问au3可以实现监控键盘状态吗?比如: 键盘按y键,可以把这个y记录下来,感谢!! 完全可以,搜索键盘钩子。 @水木子:求告知函数,谢谢{:face (361):} 回复 3# 梦想
#include <WinAPI.au3>
_WinAPI_SetWindowsHookEx ( $iHook, $pProc, $hDll [, $iThreadID = 0] ) 我学习函数_WinAPI_SetWindowsHookEx help文档中范例
请教一下,范例中Func EvaluateKey 好像没有调用?变量$iKeycode没有设定,是吗?
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $g_hHook, $g_hStub_KeyProc, $g_sBuffer = ""
Example()
Func Example()
OnAutoItExitRegister("Cleanup")
Local $hMod
$g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hMod = _WinAPI_GetModuleHandle(0)
$g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
MsgBox($MB_SYSTEMMODAL, "", "Click OK, then in notepad type..." & _
@CRLF & @CRLF & "Jon" & @CRLF & "AutoIt" & @CRLF & @CRLF & "Press Esc to exit script")
Run("notepad.exe")
WinWait("")
WinActivate("")
While 1
Sleep(10)
WEnd
EndFunc ;==>Example
Func EvaluateKey($iKeycode)
If (($iKeycode > 64) And ($iKeycode < 91)) _ ; a - z
Or (($iKeycode > 96) And ($iKeycode < 123)) _ ; A - Z
Or (($iKeycode > 47) And ($iKeycode < 58)) Then ; 0 - 9
$g_sBuffer &= Chr($iKeycode)
Switch $g_sBuffer
Case "Jon"
ToolTip("What can you say?")
Sleep (2000)
Case "AutoIt"
ToolTip("AutoIt Rocks")
Sleep (2000)
EndSwitch
ElseIf ($iKeycode > 159) And ($iKeycode < 164) Then
Return
ElseIf ($iKeycode = 27) Then ; esc key
Exit
Else
$g_sBuffer = ""
EndIf
EndFunc ;==>EvaluateKey
; ===========================================================
; callback function
; ===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndIf
If $wParam = $WM_KEYDOWN Then
EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
Else
Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")
Switch $iFlags
Case $LLKHF_ALTDOWN
ConsoleWrite("$LLKHF_ALTDOWN" & @CRLF)
Case $LLKHF_EXTENDED
ConsoleWrite("$LLKHF_EXTENDED" & @CRLF)
Case $LLKHF_INJECTED
ConsoleWrite("$LLKHF_INJECTED" & @CRLF)
Case $LLKHF_UP
ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @CRLF)
EndSwitch
EndIf
Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($g_hHook)
DllCallbackFree($g_hStub_KeyProc)
EndFunc ;==>Cleanup 回复 5# 梦想
http://61.153.183.109:88/forum.php?mod=viewthread&tid=2389&highlight=%BC%FC%C5%CC 回复 6# kk_lee69
我有看到,只是下载test.rar,没有代码,只有exe 回复 5# 梦想
如果你想知道某个函数在代码执行中是否被调用,最简单粗暴的方法就是,把这个函数给注释掉或者直接删除,看看代码执行是否报错,如果报错,那么错误是否因为该函数引起的,就一目了然了。 回复 7# 梦想
http://61.153.183.109:88/forum.php?mod=viewthread&tid=1340&highlight=%BC%FC%C5%CC%2Bqop1830 回复 8# 水木子
感谢,已经搞定
想再请教一下,consolewrite输出数据可以保存成txt文档吗? 回复 10# 梦想
我的天FileWrite {:face (197):}努力中,感谢
页:
[1]