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:
{}
Related
Here's my code below. AHK file is saved as UTF-8 with BOM and I can see the unicode characters just fine whenever I paste it into the script. But everytime I save the script and re-open it, the unicode characters become question marks and random gibberish characters. When "sendinput" is run, the output also comes out as question marks and gibberish, instead of the actual unicode emoticons.
MyVarEmoticon =
(Ltrim
What is your choice? (Enter #):
1. (╯°□°)╯︵ ┻━┻
2. (┛ಠ_ಠ)┛彡┻━┻
3. (╯°Д°)╯︵/(.□ . \)
4. ┏━┓┏━┓┏━┓ ︵ /(^.^/)
)
InputBox, MyVarEmoticonChoices, Emoticon Choices, %MyVarEmoticon%, , 400, % HEmoticon(MyVarEmoticon),,,,,1
HEmoticon(MyVarEmoticon)
{
StringReplace, MyVarEmoticon,myvaremoticon,`n,`n,UseErrorLevel
Lines:=ErrorLevel+1
height:=lines * 30 ; play with this value !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;MsgBox % height
If (Height < 40) ; too low
Height+=80
Return height
}
if ErrorLevel {
;MsgBox, CANCEL was pressed.
} else {
if (MyVarEmoticonChoices = "1"){
MyVarEmoticonChoices = (╯°□°)╯︵ ┻━┻
}
if (MyVarEmoticonChoices = "2"){
MyVarEmoticonChoices = (┛ಠ_ಠ)┛彡┻━┻
}
if (MyVarEmoticonChoices = "3"){
MyVarEmoticonChoices = (╯°Д°)╯︵/(.□ . \)
}
if (MyVarEmoticonChoices = "4"){
MyVarEmoticonChoices = ┏━┓┏━┓┏━┓ ︵ /(^.^/)
}
WinGetPos, X, Y, Width, Height, ahk_exe ToW.exe, , ,
XVar = %X%
YVar = %Y%
WVar = %Width%
HVar = %Height%
XWVar = % XVar+39
YHVar = % YVar+682
Sleep,200
sendinput, {raw}%MyVarEmoticonChoices%
Although there are some quite weird things in this code, it seems to work as expected if saved with the correct encoding.
I can't really know what goes wrong when you're trying to save it, maybe try to explain the steps you take to save it in the editor you're using.
If you don't want to worry about file encoding, you could store the characters as code points for example.
You can find a quick little converter with a Google search, here is the one I landed on with a Google search:
http://unicode.scarfboy.com/?s=%28%E2%95%AF%C2%B0%E2%96%A1%C2%B0%29%E2%95%AF%EF%B8%B5+%E2%94%BB%E2%94%81%E2%94%BB
And then you can convert to the code points to characters with Chr().
For example:
emote := "0028 256F 00B0 25A1 00B0 0029 256F FE35 0020 253B 2501 253B"
for each, codepoint in StrSplit(emote, " ")
output .= Chr("0x" codepoint)
Clipboard := output
SendInput, ^v
And here I'm also utilizing the clipboard and sending Ctrl+v, which is a good trick if you can use it. Especially for long text, which this really isn't I guess, but I figured I'd show it.
Or if you want to Send the string, you can use the Unicode notation:
emote := "0028 256F 00B0 25A1 00B0 0029 256F FE35 0020 253B 2501 253B"
for each, codepoint in StrSplit(emote, " ")
output .= "{U+" codepoint "}"
SendInput, % output
;SendInput, % "{U+0028}{U+256F}{U+00B0}{U+25A1}{U+00B0}{U+0029}{U+256F}{U+FE35}{U+0020}{U+253B}{U+2501}{U+253B}"
In ahk script files you must choose UTF-16 LE BOM Encoding to support Unicode characters. That's a Microsoft Windows default behaviour which indicates all other encodings as ASCII.
So i have an ahk script to write letters with macrons for Latin words. When you press tilde and a vowel; it types that vowel with a macron. My only problem is removes the function of the tilde key, except typing macrons. adding a ~ to keep the original keybind makes it so when i hit tilde and a vowel, it types tilde and a long vowel. How do i fix this? (this is supposed to replicate the Maori keyboard, but that was too tedious)
` & a::
send, ā
return
` & e::
send, ē
return
` & i::
send, ī
return
` & o::
send, ō
return
` & u::
send, ū
return
Add `::` to your script and backtick (`) will fire when you release the key and tilde (~) will fire on press.
https://www.autohotkey.com/docs/Hotkeys.htm#combo
Alternatively, you can use
Hotstrings
aa := Chr(257)
:?O:`a::
Send, %aa%
Return
Typing `athen pressing an ending character (like Space) creates ā.
• The "O" is an Option which omits the ending character (such as an unwanted Space).
• The "?" is an Option which allows the hotstring to be triggered inside of words, so you can type pra` then a Space and it will become prā.
• Using Hotstrings instead of Hotkeys will keep the functionality of the Tilde key unchanged.
• By default, the backtick (`) is used as the AHK escape character. For this Hotstring to work properly, the escape character should be changed. Example:
#EscapeChar \
My version of your script:
#EscapeChar \
; lower case graphemes
aa := Chr(257)
ee := Chr(275)
ii := Chr(299)
oo := Chr(333)
uu := Chr(363)
yy := Chr(563)
ae := Chr(230)
; upper case graphemes
upper_aa := Chr(256)
upper_ee := Chr(274)
upper_ii := Chr(298)
upper_oo := Chr(332)
upper_uu := Chr(362)
upper_yy := Chr(562)
upper_ae := Chr(198)
; Hotstrings
:?O:`a::
Send, %aa%
Return
:?O:`a`::
Send, %upper_aa%
Return
:?O:`e::
Send, %ee%
Return
:?O:`e`::
Send, %upper_ee%
Return
:?O:`i::
Send, %ii%
Return
:?O:`i`::
Send, %upper_ii%
Return
:?O:`o::
Send, %oo%
Return
:?O:`o`::
Send, %upper_oo%
Return
:?O:`u::
Send, %uu%
Return
:?O:`u`::
Send, %upper_uu%
Return
:?O:`y::
Send, %yy%
Return
:?O:`y`::
Send, %upper_yy%
Return
:?O:`ae::
Send, %ae%
Return
:?O:`ae`::
Send, %upper_ae%
Return
>
The above snippet saves the true ASCII values of the characters to variables (as to avoid compatibility issues), rather than trying to print the characters directly through "Send".
Other Options (and more information on Hotstrings) can be found in the Hotstrings AutoHotkey documentation.
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
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.
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