Sign in to follow this  
Followers 0
scripterman

Holding space for a specific time

8 posts in this topic

hello to everyone in the forum

I want to create a quite simple script. I need to control another window (already open) and as soon as I run the script, I need the SPACE button to be held down for a specific amount of time (defined by me), then released, then held again etc.

I had in mind something like this:

WinWaitActive("Window Title")

Send("{SPACE down}")

Sleep(2000); If I want it to be held for 2 seconds

Send("{SPACE up}")

Sleep(1000); to wait 1 sec before it is pressed again

and so on.. But it doesn't seem to work. Why?

Share this post


Link to post
Share on other sites



scripterman,

What is the window that you are trying to Send to?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

A mozilla firefox window. I used the AutoIt Window Info to copy-paste the exact name of the window.. But it doesn't work. Actually, I'm not sure 10% how the WinWaitActive command works. I mean:

- I'm in the AutoIt window writing the script and I press Go (or F5)

- Do I have to make the specific mozilla firefox window active myself by clicking in it? Then will the script start executing the commands?

Is the rest of the script ok?

Thanks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

[...]

I had in mind something like this:

WinWaitActive("Window Title")

Send("{SPACE down}")

Sleep(2000); If I want it to be held for 2 seconds

Send("{SPACE up}")

Sleep(1000); to wait 1 sec before it is pressed again

and so on.. But it doesn't seem to work. Why?

Because Sleep() means "pause the script", so pauses Send() command too.

I suggest this code to solve the problem:

WinWaitActive("Window Title")

Dim $stop_send = @sec + 2 ; Change me!!!

Do

Send("{SPACE}")

Until @SEC = $stop_send

Sleep(1000)

Send("{SPACE})

p.s. I've checked the code on SciTe, I've not written it now (like I do usually =) ).

Edited by GiulioM

Share this post


Link to post
Share on other sites

Hmmm.. It DOES send the Space key, but it doesn't hold it down for 2 seconds like I wanted to. It seems to just a press of the key. I changed the

Send("{SPACE}") to Send("{SPACE down}")

but it still doesn't work..

Share this post


Link to post
Share on other sites

scripterman,

Holding keys down is not that easy. Try this (you will need to click in the Firefox window to activate it):

WinActivate("Window Title")
WinWaitActive("Window Title")
$iOldOpt = Opt("SendKeyDownDelay", 2000)
Send("{SPACE}")
Opt("SendKeyDownDelay", $iOldOpt)
Sleep(1000); to wait 1 sec before it is pressed again

The Opt lines are saving the current setting of "the length of time a key is held down before being released during a keystroke" value, changing it to 2 secs and then resetting it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Would it be easier if I told you that I could have the same result just by holding down the left mouse button instead of the space key?

Share this post


Link to post
Share on other sites

You know I can't get the holding a button thing to work either but the left mouse click down works fine.

MouseDown ("left")
Sleep(2000)
MouseUp("left")

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