spike_s2 Posted June 7, 2008 Share Posted June 7, 2008 Function _isPressed() not capturing keys ingame. It is working properly whenever the game is not running. The game is a directx game, which runs full screen. Following is a sample code. Please let me know how to make the autoit program capture the keys that are sent ingame. Func _IsPressed($hexKey) ; $hexKey must be the value of one of the keys. ; _IsPressed will return 0 if the key is not pressed, 1 if it is. ; $hexKey should entered as a string, don't forget the quotes! ; (yeah, layer. This is for you) Local $aR, $bO $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then $bO = 1 Else $bO = 0 EndIf Return $bO EndFunc ;==>_IsPressed ..... While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case $MSG = $BTNSET ;_SetControls() ;GUICtrlSetData($MB1, $MB1Func) ;GUICtrlSetData($MB2, $MB2Func) EndSelect If _IsPressed("71") Then GUICtrlSetData($LBLSTATE, "Running") MsgBox(1,"","Capture") ;_ProcessKeys() EndIf WEnd Link to comment Share on other sites More sharing options...
d3mon Posted June 7, 2008 Share Posted June 7, 2008 Function _isPressed() not capturing keys ingame. It is working properly whenever the game is not running. The game is a directx game, which runs full screen. Following is a sample code. Please let me know how to make the autoit program capture the keys that are sent ingame. Func _IsPressed($hexKey) ; $hexKey must be the value of one of the keys. ; _IsPressed will return 0 if the key is not pressed, 1 if it is. ; $hexKey should entered as a string, don't forget the quotes! ; (yeah, layer. This is for you) Local $aR, $bO $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then $bO = 1 Else $bO = 0 EndIf Return $bO EndFunc ;==>_IsPressed ..... While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case $MSG = $BTNSET ;_SetControls() ;GUICtrlSetData($MB1, $MB1Func) ;GUICtrlSetData($MB2, $MB2Func) EndSelect If _IsPressed("71") Then GUICtrlSetData($LBLSTATE, "Running") MsgBox(1,"","Capture") ;_ProcessKeys() EndIf WEnd Try HotkeySet like that : HotkeySet("{YourKey}","Your Function") No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE Link to comment Share on other sites More sharing options...
spike_s2 Posted June 7, 2008 Author Share Posted June 7, 2008 I need to capture the left mouse button click. I don't know of a way of doing that with Hotkey. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 7, 2008 Share Posted June 7, 2008 Have you tried mouse hooks instead? Link to comment Share on other sites More sharing options...
vanowm Posted June 8, 2008 Share Posted June 8, 2008 I've seen quiet a lot talks about keyboard/mouse hooks on this forum, most of them point to some mysterious "Larry's hook" topic which is gone, so at the end, most of the topics became useless.So a little "practical" assistance regarding this would be very helpful...The thing is, directx is tend to block keyboard events for "outside" applications and without low level keyboard hook AU3 is pretty much useless tool.AutoHotkey on other hand has a very nice little feature #InstallKeybdHook and #InstallMouseHook just add these two lines to the code and you all set, your hotkey will work from most applications.In this topic you can see an example how to use keyboard hook to log the key presses (it even works in games), however I don't know how to use that method for hotkeys, where two or three keys must be pressed at the same time...It would be nice have a keyboard hook that would work with HotkeySet() function... Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 8, 2008 Share Posted June 8, 2008 Oh? I didn't even think about Larry's hooks having gone missing. Would've been nice if he didn't go deleting his posts when he disappeared. Link to comment Share on other sites More sharing options...
spike_s2 Posted June 8, 2008 Author Share Posted June 8, 2008 I found MrCreatoR's code which uses mouse hooks in order to capture mouse events.Following is the link to the post.http://www.autoitscript.com/forum/index.php?showtopic=64738I modified the code accordingly and tested it in the directx game.Still not working !!! The program is unable to capture mouse events from ingame.The code I tested. Works well outside the game.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <MouseSetOnEvent_UDF.au3> #include <GuiConstants.au3> Opt('MustDeclareVars', 1) Global $LBLSTATE Global $MBState; 1-started 0-stoped $MBState=0 ;using middle mouse button to control program ;capturing middle mouse button and enabling function _Main() ;was unable to set any other mouse buttons then left or right. for my application wheel scroll would do as well ;middle mouse botton had the windows vista function even after capture ;extra mouse button did not work at all Func MouseWheelScroll() if $MBState == 0 then ;capture LMB, enable function _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "MousePrimaryDown") ;capture started $MBState=1 GUICtrlSetData($LBLSTATE,"Capture started") ElseIf $MBState == 1 Then ;stop capture _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT) $MBState=0 GUICtrlSetData($LBLSTATE,"Capture stopped") EndIf EndFunc Func MousePrimaryDown() ;process left mouse button click ;disable capture so we can send our sequence _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT) ;send sequence MouseClick("left") sleep(100) MouseClick("right") ;reenable capture for next sequence _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "MousePrimaryDown") EndFunc Func _Main() Local $MSG, $parent $parent=GUICreate("Mouse Controls", 440, 200, 100, 100) ; will create a dialog box $LBLSTATE = GUICtrlCreateInput("Initialised: Stopped", 180, 100, 120, 30, $ES_READONLY) GUICtrlSetTip(-1, "Program State: Press middle mouse button to start/stop the program") GUISetState() ;enable wheel scroll capture _MouseSetOnEvent( $MOUSE_WHELLSCROLL_EVENT, "MouseWheelScroll") ; Run the GUI until the dialog is closed While 1 Sleep ( 100 ) $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE ;reenable wheel scroll _MouseSetOnEvent( $MOUSE_WHELLSCROLL_EVENT) Exit EndSelect WEnd EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
spike_s2 Posted June 8, 2008 Author Share Posted June 8, 2008 Link to Larry's post.http://www.autoitscript.com/forum/index.php?showtopic=55694His code is somewhat cryptic to me. If anyone could shade some light of the differences between the mouse hooks used in the previous post and Larry's hooks, you are welcome to do so. Link to comment Share on other sites More sharing options...
vanowm Posted June 8, 2008 Share Posted June 8, 2008 (edited) Yes, its a shame what happened to Larry (I've read about it on his yahoo tech group)...Anyway with hope that this might bring us one step closer to a working solution, here is Larry's keyboard hook script:expandcollapse popup#include <DllCallBack.au3> Global Const $WH_KEYBOARD_LL = 13 Global $hHook, $pStub_KeyProc Global $pStub_KeyProc = _DllCallBack ("_KeyProc","int;ptr;ptr") Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0) Global $hHook = DllCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_KEYBOARD_LL, _ "ptr",$pStub_KeyProc,"hwnd",$hmod[0],"dword",0) Global $buffer = "" While 1 Sleep(10) WEnd Func _KeyProc($nCode, $wParam, $lParam) Local $ret,$KEYHOOKSTRUCT If $nCode < 0 Then $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _ "int",$nCode,"ptr",$wParam,"ptr",$lParam) Return $ret[0] EndIf If $wparam = 256 Then $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr",$lParam) $buffer = Chr(DllStructGetData($KEYHOOKSTRUCT,1)) ToolTip($buffer) EndIf $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _ "int",$nCode,"ptr",$wParam,"ptr",$lParam) Return $ret[0] EndFunc Func OnAutoItExit() DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0]) EndFuncAnd in case you are missing DllCallBack.au3 (as I did after fresh installing lattest AU3 version) you can find it here[EDIT]While I was typing all this two replies were posted.... Edited June 8, 2008 by vanowm Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now