Paste the text from clipboard char by char - autohotkey

I'm trying to create a paste function that simulate a write "character by character" inside an input field, but my code doesn't work.
Here is my code:
^+V::
Loop, parse, clipboard, `n, `r
{
SendRaw, %clipboard%
}
return

You're trying too hard. Send command will already send key by key of whatever content you may pass into it.
; Use this in case of delaying each key press.
; SetKeyDelay, Delay
^+V::
SendRaw, %clipboard%
Return

^v::
ClipBucket5 := Clipboard
ClipBucket5 := RegExReplace(ClipBucket5, "\r\n?|\n\r?", "`n")
Loop, parse, ClipBucket5
{
SendRaw, %A_Loopfield%
Sleep, 100
}
return

Related

Why autohotkey deos not send Ctrl-Space where Space is an input

Consider the following assignment:
When I type - followed by a key, the result is Ctrl-key. This work for ordinary keys.
But when the key is whitespace, it does not work.
Any idea why this happens? And how to fix the code?
-::
Input, key, L1,{LCtrl}
send, ^{%key%}
return
Edit.
Try to run the above script a program which has Ctrl-Space as a shortcut to see that it does not work. In fact, if you press - followed by Space, the script is suppose to call Ctrl-Space but it is not the case. For example:
In Microsoft Excel or in Libreoffice Calc, Ctrl-Space can select the current column.
In Emacs Ctrl-Space is reserved for setting a Mark.
Use SendInput instead.
Tested in Excel to mimic ^a, ^x, ^v, ^space
-::
Input, key, L1,{LCtrl}
SendInput, ^%key%
Return
If you want to handle "special" keys, add those keys to the list of endkeys using this syntax
Input [, OutputVar, Options, EndKeys, MatchList]
And then check to see which endkey was pressed
Tested in Firefox to mimic ^PgDn, ^PgUp
Input, key, L1,{LCtrl}{PgUp}{PgDn}
If (ErrorLevel = "EndKey:PgUp") {
SendInput ^{PgUp}
}
Else If (ErrorLevel = "EndKey:PgDn") {
SendInput ^{PgDn}
}
Else If (ErrorLevel = "EndKey:LCtrl") {
Return ;assumed you just want to abort input with the control key
}
Else {
SendInput, ^%key%
}
Return

How to input English-Character in non-English keyboard

I'm a Chinese guy.This question trapped me very long time.This is my current method to input English-Charater ()in my Chinese-input-method:
^b::
ClipSaved := ClipboardAll
Clipboard=()
Send ^v
Clipboard := ClipSaved
Return
But,I really don't want to call the clipboard to do this thing,and the clipboard method is inconvenient to input multi-line text.Any better suggestion can give?
Note it is () but not ()
How about sending the ASCII values for left/right parentheses?
F3::
SendInput, {ASC 40}{ASC 41}
return
Output:
()
Edit for the comments:
Say we want to use other ASCII characters, such as curly braces: {}
Their decimal representations are 123 and 125 respectively.
So
F3::
SendInput, {ASC 123}{ASC 125}
return
Gets you:
{}

AHK: Assign hotkey only for one specific active window and not for others

I have just done a piece of code that does the following thing. When I make a selection by mouse in Firefox or EndNote, the script sents a Ctrl+c and checks the clipboard for a regex match. If there is a match, it changes the clipboard contents and shows a tooltip. It works fine for these two programs. Adobe Acrobat sometimes shows an error when a Ctrl+c is sent (even if a user presses a ctrl-c Acrobat sometimes shows famous "There was an error while copying to the Clipboard. An internal error occurred). So it decided to assign an F9 hotkey, but it works for all programs and not just for Acrobat. How do I assign an hotkey for only one window – Acrobat? Here's my code. I know it's lame – I am a newbie to programming in general, and in AHK in particular.
#If WinActive("ahk_exe firefox.exe") || WinActive("ahk_exe EndNote.exe") || WinActive("ahk_exe Acrobat.exe")
if WinActive("ahk_exe Acrobat.exe")
F9::
{
Clipboard:=""
send,^c
ClipWait, 1
ToolTip % Clipboard := RegExReplace(Clipboard, "\r\n", " ")
SetTimer, ToolTipOff, -1000
}
return
~LButton::
now := A_TickCount
while GetKeyState("LButton", "P")
continue
if (A_TickCount-now > 500 )
{
Send ^c
if WinActive("ahk_exe firefox.exe")
{
If RegExMatch(Clipboard, "[0-9]\.\s[A-Za-z,]*\s[A-Za-z]*")
{
regex := "[0-9]\.\s*|\s?\([^)]*\)|\."
replace := ""
}
else If RegExMatch(Clipboard,"[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}")
{
Clipboard := RegExReplace(Clipboard, "^0", "")
regex := "\/"
replace := "."
}
else return
}
else if WinActive("ahk_exe EndNote.exe")
{
If RegExMatch(Clipboard, "[a-z]+\,\s[A-Z0-9‘“]")
{
regex := "\??!?\:|\?|!"
replace := "."
}
else return
}
ToolTip % Clipboard := RegExReplace(Clipboard, regex, replace)
SetTimer, ToolTipOff, -1000
}
return
#If
ToolTipOff:
ToolTip
return
I see some very fundamental problems in the first few lines. Let me explain...
There are two types of if-statements in AutoHotkey If and #If.
You usually always use the normal If-statements unless you are doing something with hotkeys and you want specific hotkeys to be context-sensitive.
Here are some important rules:
Normal If-statements have to use curly braces {} to mark the area of code that should be executed if the expression is true. If you don't use curly braces, the If-statement will work as if you had put curly braces around the first command directly under the If-statement.
Example:
If WinActive("Firefox") {
Send, Test
MsgBox, The script just typed "Test.
}
Another example:
If WinActive("Firefox")
MsgBox, Firefox is the active window.
Normal If-statements cannot be used around a hotkey definition, but only within it.
This is allowed:
F1::
If (A_OSVersion = "WIN_7") {
MsgBox, Your operating system is Windows 7 and you just pressed F1.
}
Return
This is NOT:
If (A_OSVersion = "WIN_7") {
F1::
MsgBox, Your operating system is Windows 7 and you just pressed F1.
Return
}
But there is a way around that and that is #If-statements.
#If-statements don't use curly braces ever.
They can only be used on hotkey definitions.
And they can only be closed by another #If-statement.
(It's very common to simply use an empty #If to close it.)
Examples:
#If (A_OSVersion = "WIN_7")
F1::
MsgBox, Your operating system is Windows 7 and you just pressed F1.
Return
#If
A more complex example:
#If (A_ScreenWidth >= 1920)
F1::
MsgBox, Your your screen is at least 1920 pixels wide.
Return
F2::
MsgBox, Your operating system is %A_OSVersion%.
Return
#If (A_ScreenWidth < 1920)
F1::
MsgBox, Your your screen width is smaller than 1920 pixels.
Return
#If
As you might have guessed by now, hotkey definitions are always started by a pattern like this hotkey:: and closed by a Return. Although you can define hotkeys on a single line.
Examples:
F1::MsgBox, Hello!
F2::a ;This will remap the F2 key to an a-key.
Hotkeys by themselves do never use curly braces! Though an If-statement within a hotkey still has to use them according to the before mentioned rules.

How do i write a loop that copies and paste from the clipboard

Im trying to write a loop that copies and paste from a clipboard i titled InitialWords.txt what i acutally want is for it to copy the words line by line and press the F2 key after each word. Heres what i tried-
Loop , read C:\InitialWords.txt
{
Loop , parse , A_LoopReadLine , %A_Tab%
{
clipboard= %A_LoopField%
send ^v
send {F2}
}
}
Thanks id appreciate any help.
It appears you were missing a comma after Loop, Read. You can also bypass using the clipboard altogether.
Loop, Read, C:\InitialWords.txt
{
Loop, Parse, A_LoopReadLine, %A_Tab%
{
Send %A_LoopField%
send {F2}
}
}
Loop, Read, InitialWords.txt
{
Loop, Parse, A_LoopReadLine, %A_Tab%
{
SendPlay % A_LoopField
Sleep % strLen(A_LoopField)*2
SendPlay, {F2}
Sleep 300
}
}

Autohotkey to put the selected text in smart quotes

I need an Autohotkey script that puts the selected text in these opening and closing quotation marks:
http://www.fileformat.info/info/unicode/char/201e/index.htm - for the opening quote
and
http://www.fileformat.info/info/unicode/char/201c/index.htm - for the closing quote
So, I can select a text, press the hotkey and the text is quotes like this:
„test text“
Thank you in advance!
f1::
saved := clipboardall ; save clipboard contents
Send, ^x ; cut
Send, „%clipboard%“ ; send clipboard content with your characters around it
clipboard := saved ; restore clipboard
saved := "" ; clear saved
Return
If that doesn't work you can put the code in brackets:
f2::
saved := clipboardall
Send, ^x
Send, {U+201E}%clipboard%{U+201C}
clipboard := saved
saved := ""
Return