AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

keyboard buffer during hotstrings?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 6:22 am    Post subject: keyboard buffer during hotstrings? Reply with quote

Maybe I am missing something - I am new to hotkey - but I have a problem if I am busy typing away, and use one of my hotstrings. What happens is that the auto-replace characters get mixed in with anyrhing I type right AFTER the hotstring. Shouldn't autohotkey hold the new incoming key strokes until it is done with the autoreplace? Is there some way to make it do this?

For example - take this hotstring:
::dont::don't
If I type "d-o-n-t g-o" fast, I get mixed characters like "don' gto". It only happens if I am typing fast - but it happens often enough to be annoying.

Maybe I just type too fast?? <grin>

Thanks
Dan
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Oct 25, 2005 12:31 pm    Post subject: Reply with quote

Please test if SetBatchLines or SetKeyDelay have any positive influence. Just a guess.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Oct 25, 2005 12:35 pm    Post subject: Reply with quote

You can also test
Code:
:K-1:dont::don't

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Oct 25, 2005 1:59 pm    Post subject: Reply with quote

Yes, Toralf's key-delay suggestion above is good for these cases. You can put it into effect for all hotstrings by putting the following line above them: #Hotstring k-1

Another thing you might try is raising the script's priority:
Process, Priority,, High
This allows the script to send keystrokes faster in many cases, or at least capitalize on the target window's keyboard buffer so that your own keystrokes won't get mixed in with those of the hotstring.
Back to top
View user's profile Send private message Send e-mail
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 3:59 pm    Post subject: Reply with quote

Thanks for all the suggestions. There is a lot ot learn about Autohotkey. I had read about keydelay, but was confused originally about K0 vs K-1 - what was "the smallest possible delay"? Sounded like some Zen concept - or maybe quantum physics. Now, it seems obvious - I think once I found the longer explanation under SetKeyDelay.

Dan
Back to top
View user's profile Send private message
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 4:22 pm    Post subject: Reply with quote

Well, K-1 and Setbatchlines -1 did not seem to help, but setting the script process to high priority looks like it works - I have not been able to beat it yet!

Thanks again.

Dan
Back to top
View user's profile Send private message
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 4:42 pm    Post subject: Reply with quote

Well, I spoke too soon. None of those really prevent the situation.

Just to test it, create this script:

:*:xxx::
Process, Priority,,High
Setbatchlines -1
setkeydelay -1
send yyyyyyy
return

Then hold down the x key. You should get a string of y's. You actually get varying numbers of y's with x's mixed in. I tried it with different combinations of the suggested options.

It just seems like there ought to be an explicit function in Autohotkey that says hold new keystrokes until the script is done SENDING keystrokes.

Still, it's a great utility!

Dan
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Oct 25, 2005 5:35 pm    Post subject: Reply with quote

Could you please test this?
Code:
#Persistent
Process, Priority,,High
Setbatchlines -1
setkeydelay -1
return

:*K-1:xxx::yyyyyyy

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Tue Oct 25, 2005 9:35 pm    Post subject: Reply with quote

you can try too :
Code:
::dont::
BlockInput, on
Send, don't
BlockInput, off
Return

(not tested)
But during the execution of the Send command, what you type on keyboard is totally ignored and not recorded...
Hope it helps

@ Chris : May be a new option to the BlockInput command ?
Code:
BlockInput, on, Remember var

During the BlockInput command, the keyboard input is recorded in the "var" variable and so can be send after if needed ???
Back to top
View user's profile Send private message
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 11:49 pm    Post subject: Reply with quote

toralf wrote:
Could you please test this?


Well, it still fails if you just hold down the x key. I could not get it to fail by typing x's real fast, so it maybe good enough for normal typing - I will have to test that over the next few days.

Thanks.
Dan
Back to top
View user's profile Send private message
kronhead



Joined: 25 Oct 2005
Posts: 8

PostPosted: Tue Oct 25, 2005 11:53 pm    Post subject: Reply with quote

Nemroth wrote:
May be a new option to the BlockInput command ?
Code:
BlockInput, on, Remember var

During the BlockInput command, the keyboard input is recorded in the "var" variable and so can be send after if needed ???


BLOCKINPUT is a close fit to what I need, but I don't really want to lose the keystrokes ...

Thanks for the suggestion, tho - AHK is really a rich programming environment, and its hard for a newbie to catch all the subtleties, let alone learn all the commands.

Dan
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Oct 26, 2005 1:55 am    Post subject: Reply with quote

Nemroth wrote:
May be a new option to the BlockInput command ? ... the keyboard input is recorded in the "var" variable and so can be send after if needed ???
It's an interesting idea. I've made a note to research it more.

By the way, I tested Toralf's variation above and it worked okay on my system even when holding down the X key. Therefore, the ability of hotstrings "to keep up" is probably sensitive to CPU speed and the load on the CPU from other applications. This is aggravated by the fact that simulating keystrokes by means of the OS's build-in keybd_event() function is a high overhead operation (keybd_event apparently uses a lot of CPU time).
Back to top
View user's profile Send private message Send e-mail
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Wed Oct 26, 2005 8:52 pm    Post subject: Reply with quote

Chris wrote:
It's an interesting idea. I've made a note to research it more.

Thanks Chris.

I think there is an other possibility. May be you can use the clipboard !!! It is not the best solution in all the situations, but it can be an interesting alternative (with the help of the AHK help file...) :
Code:
::dont::
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
clipboard  = don't
Send, ^v
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved =
Return
** not tested **

As when you copy the clipboard, Windows think it's the send of only one key, it can be sufficent to be able to send your text and to see what you type to be added after the string copied rather than "inserted" between the characters copied.

May you can use too the continuation sections if you have a long text to send, like :
Code:
::dont::
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
clipboard  =
(Join`r`n
A line of text.
By default, the hard carriage return (Enter) between the previous line and this one will be written to the file.
   By default, the tab to the left of this line will also be written to the file.
By default, variable references such as %Var% are resolved to the variable's contents.
)
Send, ^v
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipSaved =
Return
** not tested **

@ Chris : to come back to my precedent proposal, after re-reading it, I think its looks like ... a key logger capability !!!

May be is it anyway a thing to consider for the future, despite everything, as AHK is already like the butcher's knife : it can do a good steak or it can be in the first page of an evening newspaper !!! It's a (very good !!!) tool, and what it does depends on what the programmer wants it to do... AHK is so powerfull that somebody with bad intentions probably already can use it for bad things ... and in the future somebody that wants to Send a string and then to send the keys typed during the execution of the Send command will can do it...

But we aren't in the wish list forum...
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Oct 27, 2005 12:28 am    Post subject: Reply with quote

The clipboard approach would be a good solution for anyone who needs to send large amounts of text with a hotstring. Thanks for demonstrating how to do it.

As for how the planned hotstrings improvements will work, I don't think there's any worry because it probably won't take the form of a built-in variable. Instead, the program will do all the buffering of the user's physical keystrokes behind the scenes, or it will use the OS's built-in SendInput() to avoid interruptions while sending the hotstring's text.
Back to top
View user's profile Send private message Send e-mail
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Thu Oct 27, 2005 1:17 am    Post subject: Reply with quote

(this post was accidentally deleted)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group