Valhalla1 Posted November 29, 2010 Share Posted November 29, 2010 (edited) I am trying to write a script which will hold down a keyboard key when the user clicks a button, and when they click another button, the key is released. There is also an exit button Here is what I have so far. It will start holding the key down when I press the button, due to the While 1 infinite loop, but pressing the button to release the key or exit doesn't work as its stuck in the loop. How can I modify it so it holds the keydown but lets off when I press the right button ? If I get rid of the While 1 loop, pressing the button only sends 1 instance of the key, it doesn't hold it down like it should. expandcollapse popupAutoItSetOption("WinTitleMatchMode", 2) ;#NoTrayIcon #include <GUIConstants.au3> #include <Date.au3> GUICreate("Basic GUI with Buttons", 205,200) GUICtrlCreateLabel ( "title goes here" , 270, 140, 200, 35 ) $Button6= GUICtrlCreateButton("Control DOWN", 20, 25, 150, 40) $Button7= GUICtrlCreateButton("Control UP", 20, 65, 150, 40) $Close= GUICtrlCreateButton("E&xit", 20, 105, 150, 40) $filemenu = GUICtrlCreateMenu ("Men&u") $Helpme = GUICtrlCreateMenuItem ( "&Help", $filemenu ) ------------------------------------------------------------------------ GUISetBkColor ( 0xFFFFFF ) GuiSetState (1) While 1 $msg = GUIGetMsg() Select Case $msg = $button6 While 1 Send("{a down}") ;Holds the A key down WEnd Case $msg = $button7 Send("{a up}") Keyup() Case $msg = $Close Exit EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Edited November 29, 2010 by Valhalla1 Link to comment Share on other sites More sharing options...
SparkSoft Posted November 30, 2010 Share Posted November 30, 2010 (edited) n Edited November 30, 2010 by SparkSoft [center]First Ever Script/App[/center][center]Simple Battery Meter[/center] Link to comment Share on other sites More sharing options...
SparkSoft Posted November 30, 2010 Share Posted November 30, 2010 (edited) expandcollapse popupAutoItSetOption("WinTitleMatchMode", 2) ;#NoTrayIcon <GUIConstants.au3> #include <Date.au3> GUICreate("Basic GUI with Buttons", 205,200) GUICtrlCreateLabel ( "title goes here" , 270, 140, 200, 35 ) $Button6= GUICtrlCreateButton("Control DOWN", 20, 25, 150, 40) $Button7= GUICtrlCreateButton("Control UP", 20, 65, 150, 40) $Close= GUICtrlCreateButton("E&xit", 20, 105, 150, 40) $filemenu = GUICtrlCreateMenu ("Men&u") $Helpme = GUICtrlCreateMenuItem ( "&Help", $filemenu ) ------------------------------------------------------------------------ GUISetBkColor ( 0xFFFFFF ) GuiSetState (1) While 1 $msg = GUIGetMsg() Select Case $msg = $button6 do Send("{a down}") ;Holds the A key down until $msg = $button6 Case $msg = $button7 do Send("{a up}") until $msg = $button7 Keyup() Case $msg = $Close Exit EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WendHere ive put in a do loop, if the button is pressed again it should stop sending a up or a down I dont know if this will work because I dont know what you want to do with the script, Edited November 30, 2010 by SparkSoft [center]First Ever Script/App[/center][center]Simple Battery Meter[/center] Link to comment Share on other sites More sharing options...
Valhalla1 Posted November 30, 2010 Author Share Posted November 30, 2010 thanks for the reply. That looked like it should work when I saw it, but when I tried it it seems to only hit the key once, not hold it down. The same thing happens if I remove the loop entirely. Curious, the Send("{a down}") command only seems to truly hold down the button if it is in a While 1 infinite loop here is the cleaned up code using your example, which doesn't truly hold down the a button like it should expandcollapse popupAutoItSetOption("WinTitleMatchMode", 2) ;#NoTrayIcon #include <GUIConstants.au3> #include <Date.au3> GUICreate("Basic GUI with Buttons", 205,200) GUICtrlCreateLabel ( "title goes here" , 270, 140, 200, 35 ) $Button6= GUICtrlCreateButton("Control DOWN", 20, 25, 150, 40) $Button7= GUICtrlCreateButton("Control UP", 20, 65, 150, 40) $Close= GUICtrlCreateButton("E&xit", 20, 105, 150, 40) $filemenu = GUICtrlCreateMenu ("Men&u") $Helpme = GUICtrlCreateMenuItem ( "&Help", $filemenu ) ;------------------------------------------------------------------------ GUISetBkColor ( 0xFFFFFF ) GuiSetState (1) While 1 $msg = GUIGetMsg() Select Case $msg = $button6 do Send("{a down}") ;Holds the A key down until $msg = $button6 Case $msg = $button7 do Send("{a up}") until $msg = $button7 Send("{a up}") Case $msg = $Close Exit EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Link to comment Share on other sites More sharing options...
SparkSoft Posted December 1, 2010 Share Posted December 1, 2010 (edited) you could use the a button with ShellExecute() command to run another script then use another button with ProcessClose() to stop it, but the script has to be compiled before you run itthis is one way to stop it going into an infinite loopSo it would go like this:Case $Button1 ShellExecute(@ScriptDir "\send a.exe" ;this is the script you wanna put a loop in and compile it Case $Button2 ProcessClose("send a.exe")and this would be the one you would need to compile and have in the same folderWhile 1 Send("a") Wend EDIT: The reason my script doesnt work is because while (no pun intended ) the script is in while loop it isnt listening for gui messages (Sorry 4 that) Edited December 1, 2010 by SparkSoft [center]First Ever Script/App[/center][center]Simple Battery Meter[/center] 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