Jump to content

Hold a key down


Recommended Posts

Hello,

I looked at many topics but did not find a working answer. I want to hold the key "a" for 3 seconds exactly as if I was pressing the "a" key on my keyboard. Is this possible?

I tried many things, including loop but it does not work like if I was using a keyboard. It repeats the "a" key very fast but this is not what I am looking for. I want to simulate a key pressed on the keyboard for X amount of time.

Any solution?

 

Thank you

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/Send.htm

from this page...

To hold a key down
    Send("{a down}") ;Holds the A key down
    Send("{a up}") ;Releases the A key

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

6 hours ago, alienclone said:

https://www.autoitscript.com/autoit3/docs/functions/Send.htm

from this page...

To hold a key down
    Send("{a down}") ;Holds the A key down
    Send("{a up}") ;Releases the A key

It does not work. I do not want to be rude but if you did not try it yourself or do not understand, please do not reply. Especially if you want to be conscendant 😕

Once again, I want to simulate holding a key down

Send("{a down}") ;

Does NOT hold the key down like a keyboard does

Link to comment
Share on other sites

6 hours ago, alienclone said:

1. You did not read my post, as I said "I looked at many topics but did not find a working answer"

2. I don't think you are here to help, but only here to troll. You are trying sarcastically to claim that I did not search even on Google...

 

I don't want to be rude but I am not grateful at all. If you want to be sarcastic/blame others and not really help don't answer 😕

Link to comment
Share on other sites

6 hours ago, alienclone said:

https://www.autoitscript.com/autoit3/docs/functions/Send.htm

from this page...

To hold a key down
    Send("{a down}") ;Holds the A key down
    Send("{a up}") ;Releases the A key

To be clear for whoever will eventually read this post one day trying the same thing (or eventually someone will prove me wrong?)

Send("{a down}")       will press the a key only once. So your tool or whatever will write "a"

If you want to write "aaaaaaaaaaaaaaa" then you can use multiple ways. A loop would work. However it's not like holding the "a" key down, it's like pressing the "a" key multiple times (which is not what I am looking for here)

 

Link to comment
Share on other sites

  • Moderators

Joualouanor,

Welcome to the AutoIt forums.

Quote

 I want to simulate a key pressed on the keyboard for X amount of time

The result of this will depend on several system variables such as the typematic rate and delay - which could result in any number of characters appearing. What exactly are you trying to achieve with this very precisely timed keypress?

And please try to tone down the sarcasm in your responses - people here do not normally troll newcomers and your explanation of your requirements was not altogether clear, hence my request for clarity above.

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

Hey Melba23,

I was not sarcastic at all. I clearly said why I did not like the previous answer and I did not use any irony. The answer given did not help and it was even slightly disrespectful.

Thank you for the info about "typematic rate and delay" I have no clue what typematic is so I will have a look at it and maybe learn something

 

This being said, I am sorry if my need were not clear enough. Here exactly what I want to achieve:

I want to simulate the action of pressing and holding a key down on my keyboard exactly as if a human was pressing and holding this key down with his finger

 

If it's not possible with AutoIT, I would understand

 

Link to comment
Share on other sites

1 hour ago, Joualouanor said:

It does not work. I do not want to be rude but if you did not try it yourself or do not understand, please do not reply. Especially if you want to be conscendant 😕

Once again, I want to simulate holding a key down

Send("{a down}") ;

Does NOT hold the key down like a keyboard does

listen up buddy, you said you tried "lots of things" but you never showed any code or even specified which functions you did try, so for me to post the CORRECT FUNCTION to perform what you asked (whether or not it was successful for you) was not being condescending.

according to the documentation for the Send function, it should do it, not my fault it doesnt work for you, so you can shove your dick up your own ass and see if that helps you because i will be sure not to help you in the future.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

It's true I was not specifically clear. I tried so much things that I did not want to write everything down in a post as it would be quite unclear. However, this is not a reason to be disrespectful.

Also, your answer was not the "CORRECT FUNCTION" as I specifically said in the very first post "I want to hold the key "a" for 3 seconds exactly as if I was pressing the "a" key on my keyboard" and your answer does not do that.

 

Back to my question, if AutoIT cannot simulate a key being pressed and hold. Maybe I can use AutoIT to activate a keyboard macro that would do the trick. What do you think people?

Link to comment
Share on other sites

; key "a" down and up for 3 seconds
#include <Misc.au3>

$timer=TimerInit()
Send("{a down}") ;Holds the A key down

While _IsPressed("41")
    Beep(1000, 100)       ; audiable proof
    If TimerDiff($timer) > 3000 Then ExitLoop
WEnd
Send("{a up}")    ;Releases the A key

#cs

Place the cursor here and press F5 ==>

#ce

 

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

I think it is still not clear what you want to achieve.  Start by explaining what application you want to automate.  Maybe someone here knows the application and can suggest a better solution than sending keys.  If the solution is effectively sending keys like you seem to look at, there is multiple ways to implement it.  What is the real end result you are expecting ?  If I was on Notepad, what would I see after those 3 secs ?  A single char, multiple char ?   

Link to comment
Share on other sites

21 minutes ago, Nine said:

I think it is still not clear what you want to achieve.  Start by explaining what application you want to automate.  Maybe someone here knows the application and can suggest a better solution than sending keys.  If the solution is effectively sending keys like you seem to look at, there is multiple ways to implement it.  What is the real end result you are expecting ?  If I was on Notepad, what would I see after those 3 secs ?  A single char, multiple char ?   

Hello, it's for a personal project.

If you open notepad, and push the "a" key down for 3 seconds, you will end up with something like this: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

I want the same result that is using what I start to understand as a kind of "repeat" function included within keyboard that would apparently be accessible only by manually pressing the key...? Not sure of that, just a feeling

 

26 minutes ago, Exit said:
; key "a" down and up for 3 seconds
#include <Misc.au3>

$timer=TimerInit()
Send("{a down}") ;Holds the A key down

While _IsPressed("41")
    Beep(1000, 100)       ; audiable proof
    If TimerDiff($timer) > 3000 Then ExitLoop
WEnd
Send("{a up}")    ;Releases the A key

#cs

Place the cursor here and press F5 ==>

#ce

 

Thank you for the answer, I do not understand it so I can't say right now if it works but I will try it later this evening

Link to comment
Share on other sites

  • Developers
12 minutes ago, Joualouanor said:

Hello, it's for a personal project.

If you open notepad, and push the "a" key down for 3 seconds, you will end up with something like this: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

...  correct... and did you actually search for the answer in our forums as this has been asked many times before?
recent example: 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

5 minutes ago, Jos said:

...  correct... and did you actually search for the answer in our forums as this has been asked many times before?
recent example: 

Jos

Yes I did and I specifically have already seen this post by the way. While it helped me to understand... I guess, it did not provide a solution. How can I "implement the repeat function in the program." exactly as the keyboard does?

Link to comment
Share on other sites

55 minutes ago, Joualouanor said:

it's for a personal project.

Ahhh, personal like in secret or like in I can't tell ?  Anyway I was able to simulate the key press with the repeat function using Notepad.  _IsPressed is true all the time and Notepad receives multiple keys. But since it is not Notepad your "personal project", I am not sure it would work in your particular case...

Link to comment
Share on other sites

  • Developers
2 hours ago, Joualouanor said:

Yes I did and I specifically have already seen this post by the way. While it helped me to understand... I guess, it did not provide a solution. How can I "implement the repeat function in the program." exactly as the keyboard does?

That wasn't clear at all looking at your previous post, while that linked topic is pretty clear I would say!
Post a replicator script else please stop bothering us with this "secret ...I can't share it". ;) 

JOs

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

3 hours ago, Jos said:

That wasn't clear at all looking at your previous post, while that linked topic is pretty clear I would say!
Post a replicator script else please stop bothering us with this "secret ...I can't share it". ;) 

JOs

A replicator script? Like my own code you mean? Here what it looks like for now. I use it on notepad:

Opt("WinTitleMatchMode",2)
WinActivate("*Untitled")

$i = 0

Do
   $i = $i + 1
   Send("a")
Until $i = 100

 

 

How can I "implement the repeat function in the program." mentioned in the thread you linked exactly as the keyboard does?

Link to comment
Share on other sites

7 hours ago, Exit said:
; key "a" down and up for 3 seconds
#include <Misc.au3>

$timer=TimerInit()
Send("{a down}") ;Holds the A key down

While _IsPressed("41")
    Beep(1000, 100)       ; audiable proof
    If TimerDiff($timer) > 3000 Then ExitLoop
WEnd
Send("{a up}")    ;Releases the A key

#cs

Place the cursor here and press F5 ==>

#ce

 

Ok so I am using it and so far it sends "a" only once on notepad. I suppose it requires some tweak?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...