Sign in to follow this  
Followers 0
Rincewind79

problem: holding down key with variable

11 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  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

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

try _ispressed() function insetead hotkeyset()

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

look for the function _ispress() on the winapiex incluedes... this func tells you wherever a key is being presed and return the number value of the key

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0