| View previous topic :: View next topic |
| Author |
Message |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Wed Aug 11, 2004 12:39 am Post subject: buffering keystrokes -- What's the best way? |
|
|
I've got a script that triggers another program to move the caret around the screen and type about a hundred characters. It takes about 1 second. The other program is a terminal emulator that does some stuff that ahk won't in this particular instance (yeah a rare instance ), so I can't incorporate that part into ahk. I want to be able to type while this is going on yet have what I type happen AFTER the other stuff. It doesn't really matter if ahk waits for 1 seconds or checks something to see if the other program is done doing it's stuff. That's not an important issue.
So how would you guys do it? The input command? I trigger the other program's macro with a single unique keypress btw. I hope this is a fun idea to brainstorm about for ya'll. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Aug 11, 2004 1:13 am Post subject: |
|
|
I think the only way to buffer your own keystrokes -- holding them "suspended" and then playing them back later -- is with the Input command, omitting the V (Visible) option. You could have that Input timeout after 1 second or have it terminated by a press of ENTER or some other end key. Once the Input has finished, you could use the SendRaw command to send whatever keys were collected (if any).
Note that currently, the Input command cannot directly collect non-character keys such as {Down} and {F4}. If that's a problem, the following topic suggests a workaround: http://www.autohotkey.com/forum/viewtopic.php?t=595 |
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Wed Aug 11, 2004 11:46 pm Post subject: |
|
|
yeah that would work pretty well. I should be able to put that to into my script. I'm not sure if it will 100% reliably catch all the keystrokes every time though. Since in between loops a key could be hit. (I could be wrong about this though, i haven't tested it.) I would be executing this portion of the code about 600 times a day for info going into a database so reliability in this case is the most important thing.
I'll probably wait until the feature is implemented into hotstrings. There are a lot of other scripts i can work on in the mean time.
Looking at the the big picture of how AHK works overall, I think buffering keystrokes is very important for it. All other programs in windows do it while they are "thinking" right? It feels constraining to have to remember not to press anything or risk those keystrokes being lost. And the uncertainty of not knowing exactly when you can start interacting with the computer again is a small but frustrating hindrance as well. Optimally I'd like to be able to do what I'm doing and not have to even glance at the screen. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Aug 12, 2004 12:38 am Post subject: |
|
|
| Quote: | | I'll probably wait until the feature is implemented into hotstrings. |
If you're referring to the ability to capture non-character keys such as {F4} and {Down} with the Input command, it might be a while before that gets implemented (since it seems rarely needed and since there's a workaround using end-keys).
| Quote: | | the uncertainty of not knowing exactly when you can start interacting with the computer again is a small but frustrating hindrance as well |
Because you're simulating keystrokes (if I understand your scenario correctly), any keys you type physically during that time will get insertted in between the artificial keystrokes. In addition, I just realized that although the Input command has an option to ignore artificial input generated by AHK itself, it does not have the option of ignoring ALL artificial input (i.e. from that other program you mentioned). Therefore, the plan might fail unless the keystrokes are sent by AHK itself. This is because the Input command would also capture and hide all of the simulated keystrokes that were intended for the target window.
A related command is BlockInput, though it might not be helpful in this particular case since you said you wanted the keys buffered, not blocked.
Finally, there is an item on the to-do list to support moving the caret in an edit window. In fact, this might be possible already by using the Post/SendMessage commands in a way discovered through means such as those in the SendMessage Tutorial. |
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Thu Aug 12, 2004 12:55 am Post subject: |
|
|
I'll look for some sort of block input command that buffers keystrokes in the other program (it's a terminal emulator). There's a good chance it has a way to do it or has a work around.
Maybe in the future AHK's BlockInput could have an option to buffer keyboard activity. Maybe someone will stumble upon this thread in a few months and add an idea or two to it. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Thu Aug 12, 2004 1:08 am Post subject: |
|
|
It seems like the more endkeys one adds to the Input command, the more If statements the loop needs to detect them, which is time spent outside of the Input command -- losing keystrokes. Then the script will have to use the BlockInput command while those If statements are running.
I'm not sure how fast I'd have to hit a key after I hit an endkey to cause it to not be buffered... I'm guessing anything's possible when there's this terminal emulator and a virus scanner taking up varying loads on the cpu at the same time.
Oh well, if other people find a need for this they'll post about it. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Aug 12, 2004 3:09 am Post subject: |
|
|
| Quote: | | Maybe in the future AHK's BlockInput could have an option to buffer keyboard activity. |
BlockInput is a feature built into the OS, which is why its behavior varies between Win9x and 2k/XP.
| Quote: | | time spent outside of the Input command -- losing keystrokes |
I don't think it's realistic to expect another key to be pressed so soon after the user has pressed an end key. If the script is running at the default SetBatchLines of 10ms (or -1, the fastest), thousands of script lines would be executed in between each pair of even the fastest typist's keystrokes.
| Quote: | | the more endkeys one adds to the Input command, the more If statements the loop needs to detect them |
You don't even need IF statements, you just need to detect when ErrorLevel contains the string "EndKey:" then use StringReplace to replace that string with a left brace, and append a right brace at the end, resulting in a character that can be sent with the Send command (though not with SendRaw -- which is what should be used for the rest of the characters gathered by the Input -- so that might be an issue). |
|
| Back to top |
|
 |
|