Jump to content

Recommended Posts

Posted

Hi,

I have the following function, which works:

Global $a = 0
Dim $keys[3] = ["{1}", _
                "{2}", _
                "{3}"]

Func test()
        $a = Mod($a+1, UBound($keys))
        Send($keys[$a])
    EndIf
EndFunc

Now I want to hold this $keys[$a] down, but everything I tried didn't work. I tried it like here:

ControlSend("WindowTitle", '', '', "{" & $Text & " Down}")

but that didn't work either. What am I doing wrong, and do I have to "unhold" this button, every time I call this function again?

Posted (edited)

The AutoIt help file (Send function) states:

To hold a key down (generally only useful for games)

Send("{a down}") ;Holds the A key down

Send("{a up}") ;Releases the A key

What do you pass as variable $Text? If it is the content of the $keys array then you need to remove the "{" and "}" from the elements of the array. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

The $Text is just from another example, I dont use that. I want to pass a key-press from the array:

"Send($keys[$a])" presses the button once, but what presses it indefinitely? I tried:

Send("{" & $keys[$a] & " Down}") and that didnt work.

Posted (edited)

Let's say you choose to send element 0 of the $keys array. This is the string "{1}". If you insert this string into the Send statement you get:

Send("{{1} Down}")

This is definitely wrong.

As I suggested in my last post: change "{1}" to "1" in your $keys array and your script should run fine.

N.B: Maybe you'll have to change "Down" into "down".

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Now I removed the {} from the array:

Global $a = 0
Dim $keys[3] = ["1", _
                "2", _
                "3"]

Func Action1()
        $a = Mod($a+1, UBound($keys))
        Send("{" & $keys[$a] & " Down}") ; down or Down doesn't matter
EndFunc

HotKeySet("{F2}","Action1")

While 1
  Sleep(100)
WEnd

but the button still gets pressed only once. Am I doing something to un-press it?

Edited by Rincewind79
Posted

It doesn't work for me too.

What do you want to achieve by pressing a key indefinitely? How do you want to stop your script and end sending the same character over and over ...?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Thats s a good question. I thought, if I call the function again, another button gets pressed, but that doesn't un-press the previous one. Is there a global "release all buttons" command?

My goal is, that at any time one of the buttons gets pressed indefinitely and I can cycle through the array of buttons.

Posted

But do you have a real "application" you are writing this script for? Or is it just for educational reasons?

If we know what "problem" the script should solve we might show you other solutions that work.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

It started out as a script for a game, I wanted to simulate a input device I don't have. Then I read about the rules regarding games, and tried to build the script my self. I'm a total script-noob and have just the most basic knowledge of programming. After investing some time, I build a functioning script (except for the "holding down"), which made me quite happy! Gaining knowledge and understanding AutoIt may become useful in future (non-game) projects.

AutoIt clearly supports holding a key down. So I just wanna know, why it doesn't work.

Guest
This topic is now closed to further replies.
×
×
  • Create New...