Jump to content

Script Help Needed


Recommended Posts

I'm farely new to autoit and have been working on a script for a game I've been playing. What I'm trying to do is add into my script, that when the Left CTRL button is pressed, It will stay down, until it is pressed again. Other then this little problem I think I'm good with the rest of my script.

Edit - I've tried so many things and nothing seems to be working. :whistle:

Edited by IAmTheManYo
Link to comment
Share on other sites

Already went through that. See what I want to do is make it so when I press CTRL it sticks, then when I press it a second time, it comes back up. In other words I want to be able to toggle CTRL being on or not, which makes it so much more complicated. I'm new to Autoit so I really can't think of any other ways to do it. I've tried putting it into the "Pause script" fuction and that didn't work either.

Link to comment
Share on other sites

Look at the help file for "Send" then look down the page for "{CTRLDOWN}"

I guess I'll have to read it to you instead:

{CTRLDOWN} Holds the CTRL key down until {CTRLUP} is sent

I'll even right the code for you:

Send("{CTRLDOWN}")
;
; The control key is now "stuck" down
;
Send("{CTRLUP}")
; The control key is now released
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I've been trying _IsPressed without much progress. Most of the time I'll be saying in my head "Yes this is going to work!" but it ends up making CTRL do nothing, or CTRL gets stuck and I can't toggle it back up, which makes me have to restart my computer. x.x

Link to comment
Share on other sites

I've been trying _IsPressed without much progress. Most of the time I'll be saying in my head "Yes this is going to work!" but it ends up making CTRL do nothing, or CTRL gets stuck and I can't toggle it back up, which makes me have to restart my computer. x.x

you're best bet is to use two hotkeys for it, like say have the 'Home' key start it, and the 'End' pause it, 'Then have 'Escape' quit.
Link to comment
Share on other sites

IDEA!! :whistle:

HotKeySet("^", "ctrldown")
HotKeySet("{esc}", "quit")

func ctrldown()
Send("{CTRLDOWN}")
sleep(300) ;EDIT so you dont get key repeat
HotKeySet("^!", "ctrlup") ;EDIT2
while 1
sleep(1000)
wend
endfunc

func crtlup()
Send("{CTRLUP}")
sleep(300) ;EDIT so you dont get key repeat
HotKeySet("^!", "ctrldown") ;EDIT2
while 1
sleep(1000)
wend
endfunc

func quit
Exit
endfunc

lol i just realized that sending crtl will activate hotkey crtl.... howabout crtl shift to turn it on/off?

Thanks IAmTheManYo

Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

ok previous idea a bust it wont take just modifyer keys as input.. hoever this does work press ctrl + z to turn it on

HotKeySet("^z", "ctrldown")
HotKeySet("{esc}", "quit")
While 1
    sleep(1000)
WEnd


func ctrldown()
    ;EDIT took out msgbox's they were for testing purposed
    Send("{CTRLDOWN}")
    sleep(300) 
    HotKeySet("^z", "ctrlup")
    while 1
        sleep(1000)
    wend
endfunc

func ctrlup()
    ;EDIT took out msgbox's they were for testing purposed
    Send("{CTRLUP}")
    sleep(300)
    HotKeySet("^z", "ctrldown")
    while 1
        sleep(1000)
    wend
endfunc

func quit()
    Exit
endfunc
Edited by smstroble

MUHAHAHAHAHA

Link to comment
Share on other sites

HotKeySet("^z", "ctrldown")
HotKeySet("{esc}", "quit")
While 1
    sleep(1000)
WEnd
func ctrldown()
    ;EDIT took out msgbox's they were for testing purposed
    Send("{CTRLDOWN}")
    sleep(300) 
    HotKeySet("^z", "ctrlup")
    while 1
        sleep(1000)
    wend
endfunc

func ctrlup()
    ;EDIT took out msgbox's they were for testing purposed
    Send("{CTRLUP}")
    sleep(300)
    HotKeySet("^z", "ctrldown")
    while 1
        sleep(1000)
    wend
endfunc

func quit()
    Exit
endfunc
Tried this and got stuck in CTRL and had to restart my computer. Lol
Link to comment
Share on other sites

Tried this and got stuck in CTRL and had to restart my computer. Lol

i think it had something to do with the CTRLUP function setting the HotKey to CTRL+Z (if you were trying to push CTRL whilst pushing Z it would not have had the desired affect because the CTRL key was already being pushed by your script :"> )

heres a variation of it using just the one function, it seems to work ok for me, pressing the Z key should trigger CTRL being held down as well as releasing it.

HotKeySet("z", "ctrldown")
HotKeySet("{ESC}", "quit")

$isdown = 0 ;var to check if the key is up or down

While 1
    sleep(100)
WEnd

Func ctrldown()
    If $isdown = 0 Then ;if it = 0 then lets push the CTRL key down
        ConsoleWrite("CTRL IS PUSHED DOWN" & @LF)
        Send("{CTRLDOWN}") ;pushes the CTRLkey down
        $isdown = 1 ;sets our var to 1 do the next time Z is pushed it will release the key
        Sleep(300)
        HotKeySet("^z", "ctrldown") ;sets our new hotkey to CTRL + Z (remember our script is holding it down now for us ;-)  )
        While 1
            Sleep(100)
        WEnd
    Else ;if the script gets here $isdown must be = to 1 so lets release our CTRL key
        ConsoleWrite("CTRL IS UP" & @LF)
        Send("{CTRLUP}") ;released the CTRL key
        $isdown = 0 ;sets our var to = 0 so the next time it (z) is pushed the key will be pressed down
        HotKeySet("z", "ctrldown") ;sets our hotkey to "z"
        Sleep(300)
        While 1
            Sleep(100)
        WEnd
    EndIf
EndFunc 

Exit
    
func quit()
    Exit
endfunc

hope this helps :whistle:

Edit: had a smiley in the middle of the code for some reason?! lol

Edited by fu2m8
Link to comment
Share on other sites

Try this, it sends them correctly but I havent tested if it works (Not sure how I would test ctrl... shift would be easier)

#Include <misc.au3>
HotKeySet("{esc}", "quit")
While 1
    sleep(10)
    If _IsPressed("11") Then CtrlDown()
WEnd
func ctrldown()
    Send("{CTRLDOWN}")
    msgbox(0,"","Key Down")
    Do
        Sleep(10)
    Until _IsPressed('11') = 1
    Send("{CTRLUP}")
    msgbox(0,"","Key Up")
endfunc

func quit()
    Exit
endfunc
Link to comment
Share on other sites

Rad - It doesnt seem to work. It sends the message boxes correctly, but no the key.

fu2m8 - Yours works great. I changed the key to alt, since z is used for something else already, but it works good. Still kind of sad that we cant get CTRL itself to toggle them, but I'll get over it. :whistle:

Link to comment
Share on other sites

Rad - It doesnt seem to work. It sends the message boxes correctly, but no the key.

fu2m8 - Yours works great. I changed the key to alt, since z is used for something else already, but it works good. Still kind of sad that we cant get CTRL itself to toggle them, but I'll get over it. :whistle:

yeh thats a system limitation that looks like it would be pretty hard to get around (_ispressed as mentioned previously might work) but even if you can get around it the hassle probably isn't worth it as long as you can live with it being another key, best of luck with it ;)

Link to comment
Share on other sites

#Include <misc.au3>
HotKeySet("{esc}", "quit")
While 1
    sleep(10)
    If _IsPressed("A3") Then CtrlDown()
WEnd
func ctrldown()
    Send("{CTRLDOWN}")
    $i = 1
    ConsoleWrite("CTRL IS PUSHED" & @LF)
    Do
        Sleep(10)
    Until _IsPressed('A3') = 0
    Do
        Sleep(10)
    Until _IsPressed('A3') = 1
    Send("{CTRLUP}")
    ConsoleWrite("CTRL IS RELEASED" & @LF)
    Do
        Sleep(10)
    Until _IsPressed('A3') = 0
endfunc

func quit()
    Exit
endfunc

This does work for me, but its only the RIGHT control... For some reason the left control didnt seem to work right, but you could try messing with it... maybe it was jus being stupid.

EDIT~Might want to make sure that ctrl is released before you switch windows, not sure why but it didnt open the window, the tabs on the task bar went dark but it didnt change windows O_o

This is wierd stuff lol

Edited by Rad
Link to comment
Share on other sites

  • 2 weeks later...

Opt("OnExitFunc", "_Exit") ;make sure to run _Exit() before closing so ctrl doesn't get stuck down
HotKeySet("+{END}", "_Exit") ;press shift+END to exit

While 1 
    If _IsPressed(0x11) Then ;if ctrl (virtual key code 0x11) is pressed
        While _IsPressed(0x11) ;don't continue until it's released
            Sleep(25)
        WEnd
        Send("{CTRLDOWN}") ;hold ctrl down
        While _IsPressed(0x11) ;don't continue until user presses and releases ctrl
            Sleep(25)
        WEnd
        Send("{CTRLUP}") ;reset the {CTRLDOWN} flag
    ;SoundPlay(@WindowsDir & "\media\tada.wav", 0) ;debug purposes
    EndIf
    Sleep(50)
WEnd

Func _IsPressed($hexKey)
    Local $ret = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
    If Not @error And BitAND($ret[0], 0x8000) = 0x8000 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Func _Exit()
    If _IsPressed(0x11) Then Send("{CTRLUP}") ;no perpetual ctrldown loops please
    Exit
EndFunc

I believe this is the code he ended up using.

Edit: commented code.

Edited by Outshynd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...