Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my AutoHotKey script, I want to freeze user input, i.e. any input from the user will not propagate to the active program, and then unfreeze and have all the input that the user typed go to the program.

In other words: I freeze, then the user types "xyz" but this is not passed to the active program, and then I unfreeze, keystrokes "xyz" are passed to the program, and then everything's back to normal and the user can type again and it'll go to the active program.

This is so while I enter a bunch of text in the program using ControlSend, the user's typing won't interfere.

Possible? How?

share|improve this question
    
I guess I should ask, are you sending all of your text with one SendInput, or do you want to freeze (turn on the user input buffer), do several computations or loops with SendInputs in them, then unfreeze (dump the user input buffer)? –  Bavi_H Sep 17 '11 at 14:55
    
If it's possible to freeze, do a bunch of stuff, then unfreeze, that would be ideal. –  Ram Rachum Sep 17 '11 at 15:06
add comment

2 Answers

If you're able to send all of your text using one SendInput, then AutoHotkey takes care of the problem for you. From the AutoHotkey Send documentation,

SendInput and SendPlay [...] buffer any physical keyboard or mouse activity during the send, which prevents the user's keystrokes from being interspersed with those being sent.

If it's acceptable to lose the user input while it's frozen (instead of buffer it and send it afterward), you can use BlockInput. Something like

BlockInput On
; Send desired text here
BlockInput Off

However, the BlockInput documentation says if it starts when keys are already down, it can block the "key up" events and cause keys to appear stuck down. So depending on when you use it, you might have to first wait for keys to be released using KeyWait.

share|improve this answer
    
But I'm using ControlSend, cause I'm sending to a specific control... –  Ram Rachum Sep 17 '11 at 15:06
    
OK. Consider updating your question so other responders understand the full picture. –  Bavi_H Sep 17 '11 at 15:11
    
Edited answer: BlockInput may be helpful. –  Bavi_H Sep 17 '11 at 15:41
    
Nah, BlockInput doesn't help me. –  Ram Rachum Sep 18 '11 at 15:42
add comment

Use the Input command.

http://autohotkey.free.fr/docs/commands/Input.htm

edit

You said:

In my AutoHotKey script, I want to freeze user input, i.e. any input from the user will not propagate to the active program, and then unfreeze and have all the input that the user typed go to the program.

In other words: I freeze, then the user types "xyz" but this is not passed to the active program, and then I unfreeze, keystrokes "xyz" are passed to the program, and then everything's back to normal and the user can type again and it'll go to the active program.

The Input command does:

; Wait for the user to press any key. Keys that produce no visible character, such as the modifier keys, function keys, and arrow keys, are listed as end keys so that they will be detected too.

Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}

You can loop this for multiple keys or it takes a string of keys as an argument.

share|improve this answer
    
I did not understand at all how that would be helpful. –  Ram Rachum Sep 12 '11 at 13:00
    
Let me quote the documentations. –  surfasb Sep 12 '11 at 16:13
    
It seems that this is intended to take input from the user. I don't want to take input from the user. In fact it's okay if the user doesn't give any input. But if he does, I want to buffer it and output it later, after I've finished sending my own input using SendInput. I have no idea how I could achieve that using Input. –  Ram Rachum Sep 13 '11 at 13:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.