Приложение в стиле Hacker Typer для Windows

1432
Kaivosukeltaja

Мне нужно сделать несколько скринкастов, демонстрирующих некоторые приемы программирования. Я уже знаю, что я собираюсь напечатать для каждого из них, и я хотел бы свести к минимуму все задержки и неловкость от опечаток и попыток подумать, что я должен был делать дальше.

Существует ли программное обеспечение, которое позволяет мне вставлять кусок текста в буфер, а затем произвольно нажимать на клавиши и выводить мой буфер в текущее активное окно по одному символу за раз? Вроде как родной настраиваемый Хакер Тайпер . Можно ли это сделать с помощью какого-нибудь скрипта AutoHotkey или чего-то подобного? Предложения для приложений для других платформ приветствуются, если их нет для платформы Windows.

4
Просто чтобы прояснить, вы хотите пюре из клавиатуры, верно? Вы не хотите, чтобы куски текста появлялись мгновенно? Dane 10 лет назад 1
Да, я хочу, чтобы один символ появлялся при каждом нажатии любой клавиши. Когда я делаю паузу, вывод должен быть также приостановлен. Kaivosukeltaja 10 лет назад 0
Вы ищете кого-то, чтобы написать скрипт AutoHotKey для вас? Dane 10 лет назад 0

2 ответа на вопрос

4
Dane

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 and , 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 else if outbound = %A_Tab% Send 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.

Потрясающие! Это прекрасно работает, за исключением исправлений GUI и некоторых настроек для моей скандинавской клавиатуры, которые я, вероятно, смогу решить с помощью онлайн-документации. Тысяча благодарностей за помощь! Kaivosukeltaja 10 лет назад 0
Ой, эй, @Kaivosukeltaja, я обновил свой сценарий, прежде чем увидел твой комментарий и согласие. Обновленный скрипт имеет графический интерфейс и несколько улучшений (особенно «SendMode InputThenPlay»). У меня есть строка в формате `a ::` для каждого ключа, который я хочу переназначить. Это может быть так же просто, как добавить пару строк с дополнительными клавишами на клавиатуре. Dane 10 лет назад 1
Праведный! Я бы снова проголосовал, если бы мог. Это отличная демонстрация силы AutoHotkey в руках того, кто знает, что он делает. Kaivosukeltaja 10 лет назад 0
0
Elliot DeNolf

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.

Это позволяет пользователю вводить по одной строке за раз, что частично там. Вы можете сделать в основном тот же сценарий, но StringSplit за символом (только не указывайте разделитель). Я боялся, что это может быть огромное количество переменных, но это тоже может быть хорошо. Кроме того, я представляю, что он хочет, чтобы при вводе текста добавлялись новые строки. Dane 10 лет назад 0