Rincewind79 Posted May 22, 2011 Share Posted May 22, 2011 Hi, I have the following function, which works: Global $a = 0 Dim $keys[3] = ["{1}", _ "{2}", _ "{3}"] Func test() $a = Mod($a+1, UBound($keys)) Send($keys[$a]) EndIf EndFunc Now I want to hold this $keys[$a] down, but everything I tried didn't work. I tried it like here: ControlSend("WindowTitle", '', '', "{" & $Text & " Down}") but that didn't work either. What am I doing wrong, and do I have to "unhold" this button, every time I call this function again? Link to comment Share on other sites More sharing options...
water Posted May 22, 2011 Share Posted May 22, 2011 (edited) The AutoIt help file (Send function) states:To hold a key down (generally only useful for games) Send("{a down}") ;Holds the A key down Send("{a up}") ;Releases the A keyWhat do you pass as variable $Text? If it is the content of the $keys array then you need to remove the "{" and "}" from the elements of the array. Edited May 22, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Rincewind79 Posted May 22, 2011 Author Share Posted May 22, 2011 The $Text is just from another example, I dont use that. I want to pass a key-press from the array: "Send($keys[$a])" presses the button once, but what presses it indefinitely? I tried: Send("{" & $keys[$a] & " Down}") and that didnt work. Link to comment Share on other sites More sharing options...
water Posted May 22, 2011 Share Posted May 22, 2011 (edited) Let's say you choose to send element 0 of the $keys array. This is the string "{1}". If you insert this string into the Send statement you get: Send("{{1} Down}") This is definitely wrong. As I suggested in my last post: change "{1}" to "1" in your $keys array and your script should run fine. N.B: Maybe you'll have to change "Down" into "down". Edited May 22, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Rincewind79 Posted May 22, 2011 Author Share Posted May 22, 2011 (edited) Now I removed the {} from the array: Global $a = 0 Dim $keys[3] = ["1", _ "2", _ "3"] Func Action1() $a = Mod($a+1, UBound($keys)) Send("{" & $keys[$a] & " Down}") ; down or Down doesn't matter EndFunc HotKeySet("{F2}","Action1") While 1 Sleep(100) WEnd but the button still gets pressed only once. Am I doing something to un-press it? Edited May 22, 2011 by Rincewind79 Link to comment Share on other sites More sharing options...
water Posted May 22, 2011 Share Posted May 22, 2011 It doesn't work for me too. What do you want to achieve by pressing a key indefinitely? How do you want to stop your script and end sending the same character over and over ...? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
monoscout999 Posted May 22, 2011 Share Posted May 22, 2011 try _ispressed() function insetead hotkeyset() Link to comment Share on other sites More sharing options...
Rincewind79 Posted May 22, 2011 Author Share Posted May 22, 2011 Thats s a good question. I thought, if I call the function again, another button gets pressed, but that doesn't un-press the previous one. Is there a global "release all buttons" command? My goal is, that at any time one of the buttons gets pressed indefinitely and I can cycle through the array of buttons. Link to comment Share on other sites More sharing options...
water Posted May 22, 2011 Share Posted May 22, 2011 But do you have a real "application" you are writing this script for? Or is it just for educational reasons? If we know what "problem" the script should solve we might show you other solutions that work. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
monoscout999 Posted May 22, 2011 Share Posted May 22, 2011 look for the function _ispress() on the winapiex incluedes... this func tells you wherever a key is being presed and return the number value of the key Link to comment Share on other sites More sharing options...
Rincewind79 Posted May 22, 2011 Author Share Posted May 22, 2011 It started out as a script for a game, I wanted to simulate a input device I don't have. Then I read about the rules regarding games, and tried to build the script my self. I'm a total script-noob and have just the most basic knowledge of programming. After investing some time, I build a functioning script (except for the "holding down"), which made me quite happy! Gaining knowledge and understanding AutoIt may become useful in future (non-game) projects. AutoIt clearly supports holding a key down. So I just wanna know, why it doesn't work. Link to comment Share on other sites More sharing options...
Recommended Posts