LeCaillou Posted December 12, 2007 Posted December 12, 2007 (edited) Hi everyone. I made a script which doesn't work the way i would like to. I need it to send the enter key each time I type a letter. The enter key has to be sent only once, whether the key i manually press is kept down or not. I hope it's clear enough ^^ Here's the code i wrote so far : #include <Misc.au3> $var1=57 $var2=58 $var3=43 $var4=56 $var5=42 while 1 If _IsPressed($var1) Then Send("{Enter}") ExitLoop EndIf Wend For now each time i press that key the enter key is sent every few ms... I know the while is the cause but i don't know how i could adapt the code to do what i explained above. Thanks for reading and eventually answering me Edited December 12, 2007 by LeCaillou
DW1 Posted December 12, 2007 Posted December 12, 2007 (edited) use this instead: while 1 If _IsPressed($var1) Then While _IsPressed($var1) Sleep(10) WEnd Send("{Enter}") ExitLoop EndIf Sleep(10) Wend EDIT: I don't know what the rest of your code looks like, but I don't know if you want the "ExitLoop" to be there or not Edited December 12, 2007 by danwilli AutoIt3 Online Help
LeCaillou Posted December 12, 2007 Author Posted December 12, 2007 (edited) I can't use your code because i need enter to be sent as soon as i press the key, not when i release it. More than that enter has to be sent only once, no matter how long i keep the key pressed. That's also why i tried exitloop in fact EDIT : The whole code is there, i wrote down the keys code but im doing my tests with one only. Edited December 12, 2007 by LeCaillou
Valuater Posted December 12, 2007 Posted December 12, 2007 Mayb42 e... #include <Misc.au3> ; for testing Run("notepad.exe") WinWaitActive("") $var = StringSplit("57,58,43,56,42", ",") $hold_key = "" While 1 For $x = 1 To $var[0] If $var[$x] <> $hold_key And _IsPressed($var[$x]) Then Send($var[$x] & "{Enter}") $hold_key = $var[$x] ExitLoop EndIf Sleep(1) Next WEnd56 8)
LeCaillou Posted December 12, 2007 Author Posted December 12, 2007 Oh it almost works It also sends "57", "46" and other numbers while it sends enter (we can see that on your post too xD). I jsut need to tune it up i think. Can you still explain me the use of the for next here ? If i need to press the same key twice, to send twice enter after each of em your code doesn't work. Any way to fix that ? Thanks anyway
DW1 Posted December 12, 2007 Posted December 12, 2007 If you need enter on press rather than release, just change the order like I did below. If you don't need the exitloop then I got rid of it. while 1 If _IsPressed($var1) Then Send("{Enter}") While _IsPressed($var1) Sleep(10) WEnd EndIf Sleep(10) Wend It looks like Valuater has a good script going that should do what you want, but if it doesn't work give mine a shot... Start with Valuater's code though, as he is a guru AutoIt3 Online Help
LeCaillou Posted December 13, 2007 Author Posted December 13, 2007 TY danwilli, it works almost fine. Some keys still bug but its a matter of timing i think. Gonna try yo tune that up. Thanks for the help mates
DW1 Posted December 13, 2007 Posted December 13, 2007 Keep in mind that while one key is pressed, none of the other triggers are going to catch other key presses AutoIt3 Online Help
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