Sign in to follow this  
Followers 0
Unregistered

Simple Hold Button X Seconds incl. Hotkey

22 posts in this topic

Hello,

I already raped google quite a bit and tested multiple solutions but couldn't find anything that works with the most recent version of auto-it.

All I want to do is the simple following.

Hotkey CTRL+Y = Start holding Y for 20 seconds, release for 10 miliseconds, rinse and repeat

Hotkey CTRL+X = Start holding X for 20 seconds, release for 10 miliseconds, rinse and repeat

Hotkey CTRL+C = Start holding C for 20 seconds, release, press W for 10 miliseconds, release, rinse and repeat

Hotkey CTRL+V = Start holding V for 20 seconds, release, press W for 10 miliseconds, release, rinse and repeat

But the only thing I get to manage is the kill-switch

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit 0
EndFunc

Could anyone help me out ? :/

Share this post


Link to post
Share on other sites



Hello,

does it matter much ?

Just trying to figure out how that works.

kind regards

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Hello,

I wanna HOLD the key, not spam it.

And that is exactly what I would like to know, how I can hold them for a set duration like described above.

kind regards

Share this post


Link to post
Share on other sites

Perhaps "spam" was a bit poetic, but ostensibly when you hold a key it does send the key over and over?

The Send function can be used to hold a key down.  For timing you can rely on a timer (TimerInit | TimerDiff) in a loop or a simple Sleep.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Unregistered, first off welcome to the forum. Secondly, you are being asked for more information by experienced members of this forum for a reason. The more you explain in detail about what you're trying to do, the more help you will receive. The more your answers lean toward "what does it matter why, just give me what I want", the less likely people will be to assist. Help us help you ;)

Edited by JLogan3o13
1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hello,

as stated, I have no direct what ever I could I have.

I just want to understand how I do this what I have described and even if you now ask again, if I don't have anything in particular I can't tell.

Or is a simple "Hold Key for X seconds, release it and press it again", at least what sounds simple, that complicated that there are some prerequisites or that this is not possible? If so, I seem to have the wrong software.

Thought Auto-IT would be exactly for that kind of stuff and thus I want to learn to understand it, but if I first need a reason, then I'm gonna look somewhere else for a help, but still thanks! :)

kind regards

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The AutoIt help file is very useful for learning and contains examples for the functions I mentioned above. Long time forum posters are also congnicent of the forum rules (at the bottom of each page) which prohibit the discussion of certain automation tasks, such as game related automation.  Things like sending key strokes for durations are often red flag indicators for this usage--as are unclear responses to direct inquiries of intention. We cannot regulate how you use AutoIt on your own, but we try to hold ourselves accountable on this forum and adhere to the rules put in place.

Edited by spudw2k
1 person likes this

Share this post


Link to post
Share on other sites

The Send and Timer (both Init and Diff) functions can be used to do this, as was mentioned. Here you'll find some useful information - http://www.autoitscript.com/autoit3/docs/


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Hello,

so because some people use it for gaming stuff, I need to offer some full high valid whatever to gain help?

Then please add this in the registration information for new users, as I came here for some help and took, at least something that looked easy/simple for me, something simple.

And yes I read and used the docs but I do not manage to get something to run, except the hotkey for killing the script, which alone doesn't help me.

So then that's it for auto-it. I don't wanna do some dissertation just on a simple "Hold Button" Help.

It's really sad but well, still thanks. If maybe anyone might be able to help, my InBox is still open, since holding a button is against the board rules as I now have learned...

Farewell~~

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I see several responses that directed you on where to look. You may have missed them as you opined on the unfairness of having to answer questions from those trying to help you (the horror!).

If a simple question from someone trying to better understand what you're trying to accomplish is enough to get you to drop the language, so be it. I think AutoIt will get along just fine without you. :bye:

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Share this post


Link to post
Share on other sites

..yes I read and used the docs..

I guess you missed the part, IN THE DOCS, where the Send function accepts both the UP and DOWN arguments? There are lots of tutorials for AutoIt, see the Wiki - http://www.autoitscript.com/wiki. There is example code, IN THE DOCS, for just about every native AutoIt function, including Loops (If..Then, While..WEnd, read the Language Reference section IN THE DOCS). Good luck with your project. I mean that last sentence sincerely, I'm not trying to be a smart-ass. :)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Hello,

I guess you missed the part, IN THE DOCS, where the Send function accepts both the UP and DOWN arguments? There are lots of tutorials for AutoIt, see the Wiki - http://www.autoitscript.com/wiki. There is example code, IN THE DOCS, for just about every native AutoIt function, including Loops (If..Then, While..WEnd, read the Language Reference section IN THE DOCS). Good luck with your project. I mean that last sentence sincerely, I'm not trying to be a smart-ass. :)

As stated, I did read the docs and tried to use some stuff from there, but sadly nothing works as I want it (as described in my first post), could be that I missed some infos but as a new one on this tool it should be acceptable that I don't instantly inherit the whole docs.

A simple send("y down"); sleep(1000); send("y up"); works but trying to loop it, combined with a hotkey, no chance. It won't do a thing.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Post the code you're using for the loop and hotkey, so we can see what you're doing exactly.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Here a tiny fish to start fishing.
But please buy a net and try to fish yourself.

ShellExecute("notepad")
$handle = (WinWait("[Class:Notepad]", "", 0) ? (WinActivate("[LAST]") ? WinWaitActive("[LAST]") : 0) : SetError(1, 0, 0))
ControlSend($handle, "", "Edit1", "Press CTRL{+}Y to start" & @LF)
If HotKeySet("{ESC}", "_Hotkey") = 0 Then Exit MsgBox(16 + 262144, "Hotkeyset Error", "Hotkey {ESC} already set.")
If HotKeySet("^y", "_Hotkey") = 0 Then Exit MsgBox(16 + 262144, "Hotkeyset Error", "Hotkey {Ctrl+y} already set.")
While 1
    Sleep(10)
WEnd

Func _Hotkey()
    Switch @HotKeyPressed
        Case "{ESC}"
            Exit Beep(1000, 100) + WinKill($handle)
        Case "^y"
            ControlSend($handle, "", "Edit1", "Start of keypress CTRL{+}Y" & @LF)
            $time = TimerInit()
            While TimerDiff($time) < 5000 ; type 'y' for 5 seconds
                ControlSend($handle, "", "Edit1", "y")
            WEnd
            ControlSend($handle, "", "Edit1", @LF & "End of keypress CTRL{+}Y" & @LF & "Press ESC to exit" & @LF)
    EndSwitch
EndFunc   ;==>_Hotkey

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Global $Paused
HotKeySet("{y}", "TogglePause")
 HotKeySet("{ESC}", "Terminate")
 While 1
    Send("{y down}")
Sleep(1000)
Send("{y up}")
 WEnd
 Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

This is my first attempt but not really working.

Share this post


Link to post
Share on other sites

You are not following the example by @Exit.  You start off with a loop that sends the keys ...

While 1
    Send("{y down}")
Sleep(1000)
Send("{y up}")
 WEnd

I don't think you would get out of that loop.  "While 1" will always be true.  When you declare the global variable $paused it is not initialized to anything.  The toggle function will set it to "NOT $paused" which equates to true.   Then it should trigger that second loop where you would see a tooltip message every 100 milliseconds (1/10 of a second).  This snippet simulates what is happening in that function.  In my example I am not using tooltip - just writing a number to the console, and I have a way to get out the loop after 100 passes.

global $variable
MsgBox("","",$variable)
$variable = NOT $variable
MsgBox("","",$variable)
$count=0
while $variable
    $count+=1
    ConsoleWrite($count&@crlf)
    if $count=100 Then
        ConsoleWrite("exited")
        ExitLoop
    Endif
wend

Exit's example sends the keys during a set duration of time and occurs outside of the while loop.  His while loop is just to keep the application running (without out it the code would all be executed 1 time and then exit).  He is using a switch to "listen" for the hotkeys and then perform the actions under the "case" in the switch.  You are also missing the concept of the timer in @Exit's example that would perform the action for a duration of time (i.e. the 20 second requirement from you OP). 

Have you tried running @Exit's code?  It does almost exactly what you are looking for with some minor modifications.  I would run his code and then study line by line what it is doing.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Hello,

no I didn't even see the code from exit. Must have been written while I copied the code from my tests and I must say that I don't understand his code.

Also not the part with notepad?

And about your comment to my code: Yes I do not WANT to get out of the loop, thats why I wanted a loop.

When I Press ESC, the script kills itself -> Loop ended. Also When I tap the hotkey it should end the loop I am in.

I tried it the way with just one button and not all I needed. The script starts paused, and when I hit "y" the script unpauses and sends the key down for 1000 miliseconds, releases and repeats until I quit the script or pause again.

At least thats what I wanted to achieve.

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