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.

I need to do a bunch of screencasts that demonstrate some programming techniques. I already know what I'm going to type for each of them, and I'd like to minimize all the delays and awkwardness from typos and trying to think what I was supposed to do next.

Is there a software that lets me paste a chunk of text into a buffer and then randomly mash at keys and have my buffer be output into the currently active window one character at a time? Kind of like a native customizable Hacker Typer. Could it be done with some kind of AutoHotkey script or something similar? Suggestions for applications for other platforms are welcome if none exist for the Windows platform.

share|improve this question
1  
Just to be clear, you want to have to mash the keyboard, right? You don't just want the chunks of text to instantly appear? –  Dane Sep 6 '13 at 21:01
    
Yes, I want one character to appear each time I press any key. When I pause, the output should pause as well. –  Kaivosukeltaja Sep 7 '13 at 5:33
    
Are you looking for someone to write the AutoHotKey script for you? –  Dane Sep 10 '13 at 13:54

2 Answers 2

up vote 4 down vote accepted

Yes, you can use AutoHotKey. I'm sure somebody else could whip this up in no time, but I can at least imagine a possible structure to the script:

  1. Define a Suspend hotkey and start suspended, so that you can use your keyboard when you don't want to be mashing. Alternatively, or in addition, use #IfWinActive to restrict the mashing-keys function to the one window within which you will be doing this.
  2. Read a plain-text file into memory.
  3. Stack multiple hotkey definitions for pretty much every key on the keyboard for your one script action.
  4. Use StringLeft and StringTrimLeft to retrieve a single character from your big variable and delete it from the variable.
  5. Use Send to send the character that you grabbed. You may need to do a little replacement or conditional to handle sending {Enter} and {Tab}, but maybe not.

Here's my script:

#UseHook        ; Avoid loops of the Send command triggering the hotkey again.
AutoTrim, Off   ; Don't auto-trim spaces and tabs from the beginning and end of the sourcetext.
SendMode InputThenPlay  ; Try to prevent the user from corrupting the buffer text.

Suspend, On     ; Start suspended

FileRead, MasherBuffer, magic-button-masher-text.txt
if ErrorLevel
    MasherBuffer = Type or paste text here. You can also drag-and-drop text files here.

Gui, +Resize +MinSize400x200
Gui, Add, Text,, When you are ready, un-suspend this script (Ctrl and `` together will toggle the suspension).`nType any character on the main QWERTY keyboard to send the characters from the buffer instead.
Gui, Add, Edit, vMasherBuffer, %MasherBuffer%
Gui, Show,, Magic Button Masher Buffer
Return

GuiSize:
if ErrorLevel = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the MasherBuffer control to match.
NewWidth := A_GuiWidth - 20
NewHeight := A_GuiHeight - 50
GuiControl, Move, MasherBuffer, W%NewWidth% H%NewHeight%
return

GuiDropFiles:
Loop, parse, A_GuiEvent, `n
{
    FileRead, AddToBuffer, %A_LoopField%
    MasherBuffer = %MasherBuffer%`n`n%AddToBuffer%
}
GuiControl,, MasherBuffer, %MasherBuffer%
return

^`::Suspend

!`::Gui, Show,, Magic Button Masher Buffer

;   #IfWinActive ahk_class Notepad  ; This limits the button masher to Notepad.
`::
1::
2::
3::
4::
5::
6::
7::
8::
9::
0::
-::
=::
q::
w::
e::
r::
t::
y::
u::
i::
o::
p::
[::
]::
\::
a::
s::
d::
f::
g::
h::
j::
k::
l::
`;::
'::
z::
x::
c::
v::
b::
n::
m::
,::
.::
/::
Space::
GuiControlGet, MasherBuffer
StringLeft, outbound, MasherBuffer, 1
StringTrimLeft, MasherBuffer, MasherBuffer, 1
GuiControl,, MasherBuffer, %MasherBuffer%
if outbound = %A_Space%
    Send {Space}
else if outbound = %A_Tab%
    Send {Tab}
else
    Send {%outbound%}
return

You can make this only work in Notepad by uncommenting the #IfWinActive bit.

I have Ctrl+` defined as a hotkey to suspend the script.

share|improve this answer
    
Awesome! That works perfectly, aside from the GUI fixes and some adjustments for my Scandinavian keyboard which I'll probably be able to tackle with the help of the online docs. A thousand thanks for the help! –  Kaivosukeltaja Sep 10 '13 at 19:16
1  
Ooh, hey, @Kaivosukeltaja, I updated my script before I saw your comment and acceptance. The updated script has a GUI and a few improvements (especially the "SendMode InputThenPlay"). I have a line in the format of a:: for every key I want to remap. It may be as simple as adding a couple lines with the additional keys on your keyboard. –  Dane Sep 10 '13 at 20:42
    
Righteous! I'd upvote again if I could. This is a great demonstration of AutoHotkey's power in the hands of someone who knows what he's doing. –  Kaivosukeltaja Sep 11 '13 at 6:14

I wrote out what Dane described. This should do the trick. It reads in a text file, splits by line, then inputs the characters of that line one by one with a configurable delay.

FileRead, text, C:\test.txt
/* Alternatively:
text =
(ltrim
this is the first sentence.
sentence 2 here.
sentence 3 hello.
sentence 4 reporting in.
)
*/

pos := 1
StringSplit, lines, text, `n

^Space:: ; Ctrl + Space
    line := lines%pos%
    loop, Parse, line
    {
        SendInput % A_Loopfield
        Sleep 100 ; Adjust this for delay between keys
    }
    ++pos
Return

I wasn't too sure on the "mashing" of buttons, so I did not include anything in regards to that.

share|improve this answer
    
This lets the user input one line at a time, which is part-way there. You could do basically the same script, but StringSplit by character (just don't specify a delimiter). I was afraid that might be an extreme number of variables, but it might be fine too. Also, I'm imagining that he wants newlines added as he types. –  Dane Sep 10 '13 at 13:53

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.