Jump to content

Holding space for a specific time


Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

scripterman,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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

Link to comment
Share on other sites

[...]

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...