Joualouanor Posted February 8, 2020 Share Posted February 8, 2020 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 More sharing options...
alienclone Posted February 8, 2020 Share Posted February 8, 2020 https://www.google.com/search?hl=en&as_q=key+down&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fwww.autoitscript.com&as_occt=any&safe=images&as_filetype=&as_rights= 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 More sharing options...
alienclone Posted February 8, 2020 Share Posted February 8, 2020 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 6 hours ago, alienclone said: https://www.google.com/search?hl=en&as_q=key+down&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fwww.autoitscript.com&as_occt=any&safe=images&as_filetype=&as_rights= 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Moderators Melba23 Posted February 8, 2020 Moderators Share Posted February 8, 2020 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
alienclone Posted February 8, 2020 Share Posted February 8, 2020 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Exit Posted February 8, 2020 Share Posted February 8, 2020 ; 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 More sharing options...
Nine Posted February 8, 2020 Share Posted February 8, 2020 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 ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Network_Guy Posted February 8, 2020 Share Posted February 8, 2020 in short if u try to send "a" down for a game or a full window app it may or may not work and its totally depend on the game or app . Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2020 Developers Share Posted February 8, 2020 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Nine Posted February 8, 2020 Share Posted February 8, 2020 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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2020 Developers Share Posted February 8, 2020 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 seadoggie01 1 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Joualouanor Posted February 8, 2020 Author Share Posted February 8, 2020 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 More sharing options...
Recommended Posts