Sign in to follow this  
Followers 0
InjkttxD

Sticky Key?

15 posts in this topic

Hey guys, i've tried using this code to hold down the LCTRL button but i can't get it too terminate or pause the script.

It's like the button is sticky, i've manually terminated the script but my pc still thinks the LCTRL button is held down until i actually physically push it down on my keyboard and release it. Then everything works fine.

I'm so confused ;)

Global $Paused
HotKeySet("{TAB}", "TogglePause")
HotKeySet("{\}", "Terminate")
HotKeySet("+!d", "ShowMessage")  
While 1
Send("{LCTRL down}")
WEnd
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(25,"","")
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

welcome to au3 forum

every up has a down

Func Terminate()
    Send("{LCTRL up}")
    Exit 0
EndFunc

at least call it when you exist the program

OnAutoItExitRegister( "Terminate" )
Edited by trung0407

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You need a sleep function...

Global $Paused

HotKeySet("{TAB}", "TogglePause")
HotKeySet("{\}", "Terminate")
HotKeySet("+!d", "ShowMessage")

While 1
    Send("{LCTRL down}")
    Sleep(50)
WEnd

Func TogglePause()
    $Paused = Not $Paused

    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd

    ToolTip("")
EndFunc ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc ;==>Terminate

Func ShowMessage()
    MsgBox(25,"","")
EndFunc ;==>ShowMessage

Actually, scratch that. That isn't true.

Ok, I would like to add that you don't need the Send statement inside of a while loop.

Global $Paused

HotKeySet("^{TAB}", "TogglePause")
HotKeySet("{\}" , "Terminate")
HotKeySet("+!d" , "ShowMessage")

Send("{LCTRL down}")

While 1
    Sleep(50)
WEnd

Func TogglePause()
    $Paused = Not $Paused

    ToolTip("Script is 'Paused'")

    Send("{LCTRL up}")

    While $Paused
        Sleep(50)
    WEnd

    ToolTip('')
EndFunc ;==>TogglePause

Func Terminate()
    Send("{LCTRL up}")
    Exit
EndFunc ;==>Terminate

Func ShowMessage()
    MsgBox(25, "", "")
EndFunc ;==>ShowMessage
Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

I've tried both, with no prevail. My pc still thinks the LCTRL key is pressed down, even once i release it or termiate the script. Unless someone can see what i've done wrong?

Global $Paused

HotKeySet("{TAB}", "TogglePause")
HotKeySet("{\}", "Terminate")
HotKeySet("+!d", "ShowMessage")

While 1
    Send("{LCTRL DOWN}")
    Sleep(50)
WEnd

Func TogglePause()
    $Paused = Not $Paused

    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd

    ToolTip("")
EndFunc ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc ;==>Terminate

Func ShowMessage()
    MsgBox(25,"","")
EndFunc ;==>ShowMessage

or

Global $Paused
HotKeySet("{TAB}", "TogglePause")
HotKeySet("{\}", "Terminate")
HotKeySet("+!d", "ShowMessage")  
While 1
Send("{LCTRL down}")
WEnd
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Send("{LCTRL up}")
    Exit 0
    
EndFunc


Func ShowMessage()
    MsgBox(25,"","")
EndFunc

Share this post


Link to post
Share on other sites

you need

OnAutoItExitRegister( "Terminate" )

to prevent unexpected interruption of the program, which will never call the Terminate() function.

And you need to throw out the idea of placing a Send({.. down}) inside a loop of your head since one call is enough.

Share this post


Link to post
Share on other sites

Nope doesn't help i've already, looked at that, but thanks anyway ;)

you need

OnAutoItExitRegister( "Terminate" )
to prevent unexpected interruption of the program, which will never call the Terminate() function.And you need to throw out the idea of placing a Send({.. down}) inside a loop of your head since one call is enough.

So what would the whole script look like with out the continuous LCTRL key repeat?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

So what would the whole script look like with out the continuous LCTRL key repeat?

If you'll look at my revised post #3 you'll find an example...

Please only bump posts every 24 hours.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

I've tried your example and i still can't get my pc to stop thinking i've still got the LCTRL pressed down, it's really starting to frustrate me -.-

Share this post


Link to post
Share on other sites

I've tried your example and i still can't get my pc to stop thinking i've still got the LCTRL pressed down, it's really starting to frustrate me -.-

Well, I only posted that not as a fix to your problem but that the Send() being in a while loop might just introduce it's own bug, who knows.

Share this post


Link to post
Share on other sites

Well, thanks for the help (: it is really appreciated. Gives me an error now something about 'Script did not respond, forcing abortion" or something like that

Share this post


Link to post
Share on other sites

Strange, it isn't working for me anymore. I wonder what happened?!

yours stop working because you forgot to ctrl down again once the script stops pausing.

But putting a ctrl down out of the loop like you did is the correct way to do it.

Share this post


Link to post
Share on other sites

I am trying to build this same script actually, but I replaced LCTRL with "a"

but when I use example #3 it only sends 1 instance of "a", even though I have Send("{a down}")

it should be holding down the button until Send("{a up}") but it doesn't

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0