Jump to content

Holding down keyboard keys


Recommended Posts

Hello all.  So I am trying to write what I thought was going to be a simple script, but I am having a surprisingly hard time with it.  I want to have this script just hold down the enter key for a particular length of time.  That is it.  I was initially thinking about using something like this:

Send ( "{ENTER DOWN}", 0 )
Sleep ( 10000 )
Send ( "{ENTER UP}", 0 )

Seemed like something that would work in theory, but in practice (using a notepad document to test) the key does not appear to be held down at all, but simply pressed, as only one line is added to the notepad document.  I even tried something like this hoping it might work:

Opt ("SendKeyDownDelay", 15000)
Send ( "{ENTER DOWN}", 0 )
Sleep ( 5000 )
Send ( "{ENTER UP}", 0 )

But it does the same thing: adding only one line to the notepad document as you would expect when the enter key is pressed, not held down.  Am I doing something wrong/misunderstanding something as to how to do this?

Link to comment
Share on other sites

  • Developers

There is a big difference between the auto-repeat function of the keyboard when a key is pressed and the DOWN function.

Simply make a for...next loop with a Send enter and a Sleep() for the appropriate period to simulate what a keyboard does. :)

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

4 hours ago, Jos said:

There is a big difference between the auto-repeat function of the keyboard when a key is pressed and the DOWN function.

Simply make a for...next loop with a Send enter and a Sleep() for the appropriate period to simulate what a keyboard does. :)

Jos

Would you mind explaining the difference?  I guess i want to understand why the "down" function is even available if the actions which are normally associated with holding the key down (the auto-repeat) aren't emulated too.  What's the use?😕

Edited by MattHiggs
Link to comment
Share on other sites

1 hour ago, MattHiggs said:

What's the use?

Try to imagine how you would implement this : while key A is pressed, press key B.  Without the "down" function it would not be possible to implement it with the Send function.  You would need to use some more sophisticated ways to do it like hooks or messages.

Link to comment
Share on other sites

  • Developers

As stated: The auto repeat is a keyboard function not a system function, so the keyboard sends the repeated keydown/up when holding a key down. 
Since you emulate the keystrokes now with AutoIt3, you need to implement the repeat function in the program. 

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

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