Champak Posted March 27, 2008 Share Posted March 27, 2008 Here is the essence of a code I have. So I don't have to remember the shift/ctrl/alt key symbols, it will send the symbol of the key to the input box when I press it. while 1 If WinGetState($AppTitle, "Set Hotkeys") = 15 Then If _IsPressed("10") Then;Shift _PressedShift() EndIf If _IsPressed("11") Then;Control _PressedControl() EndIf If _IsPressed("12") Then;Alt _PressedAlt() EndIf EndIf wend Func _PressedShift();Shift Send("+", 1) EndFunc Func _PressedControl();Control Send("^", 1) EndFunc Func _PressedAlt();Alt Send("!", 1) EndFunc The problem is when I press the key, it just continues to send and I have to exit the program. How do I fix this? Link to comment Share on other sites More sharing options...
BillLuvsU Posted March 27, 2008 Share Posted March 27, 2008 how about you give us the actual code? As far as I can see there is no error in that one. [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
-Ultima- Posted March 27, 2008 Share Posted March 27, 2008 (edited) The code demonstrates the problem just fine... My guess is that the while loop is repeating itself very quickly, but the Send() function isn't keeping up (it's probably delayed -- Opt('SendKeyDelay')), which makes it look like it's going infinitely. Example? #include <misc.au3> $i = 0 while 1 if _ispressed("10") then ; shift pressed consolewrite($i & @CRLF) $i += 1 endif wend Run the script in SciTE. You'll notice how large the number gets after a split second of "holding" Shift. Edited March 27, 2008 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
Champak Posted March 27, 2008 Author Share Posted March 27, 2008 Thanks ultima, you sent me in the right direction and I fixed it, but there was no sendkeydelay in the script. Here's what I did. Func _PressedShift();Shift If TimerDiff($iTimerKeyPress) > 250 Then $iTimerKeyPress = TimerInit() Send("+", 1) EndIf EndFunc Func _PressedControl();Control If TimerDiff($iTimerKeyPress) > 250 Then $iTimerKeyPress = TimerInit() Send("^", 1) EndIf EndFunc Func _PressedAlt();Alt If TimerDiff($iTimerKeyPress) > 250 Then $iTimerKeyPress = TimerInit() Send("!", 1) EndIf EndFunc Link to comment Share on other sites More sharing options...
-Ultima- Posted March 27, 2008 Share Posted March 27, 2008 (edited) You're probably better of inserting a Sleep() statement outside of the if statement in the While loop, like so:#include <misc.au3> $i = 0 while 1 if _ispressed("10") then ; shift pressed consolewrite($i & @CRLF) $i += 1 endif sleep(100) wendWhy? Well, assuming you're still using a loop similar to the one you had in the first post, it kills a LOT of CPU time needlessly (you don't need to know that quickly whether a key is pressed... right?). Edited March 27, 2008 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
Champak Posted March 27, 2008 Author Share Posted March 27, 2008 Actually that is no good for me. 1, my loop is pretty large and 2, when I put a loop in it makes a lot of my other functions that rely on Case button presses very sluggish...and I only had a sleep(50). I actually took out the sleep() in the loop in this app a while ago. Link to comment Share on other sites More sharing options...
DW1 Posted March 27, 2008 Share Posted March 27, 2008 No need to use a static time delay while 1 If WinGetState($AppTitle, "Set Hotkeys") = 15 Then If _IsPressed("10") Then;Shift While _IsPressed("10") Sleep(10) WEnd _PressedShift() EndIf If _IsPressed("11") Then;Control While _IsPressed("11") Sleep(10) WEnd _PressedControl() EndIf If _IsPressed("12") Then;Alt While _IsPressed("12") Sleep(10) WEnd _PressedAlt() EndIf EndIf wend Func _PressedShift();Shift Send("+", 1) EndFunc Func _PressedControl();Control Send("^", 1) EndFunc Func _PressedAlt();Alt Send("!", 1) EndFunc AutoIt3 Online Help 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