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
Related
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 need to determine the path and file name of an open text file, whether it is opened in Notepad3 or in Emacs.
For both editors the path and file name are displayed in the window title of the opened file. Hence, I can use the AHK function WinGetTitle to extract the window title, and then the function SubStr to extract the path and file name from the window title.
However, the two editors differ in how the path and filename are displayed in the window title. In Notepad3 the title format is [filename][path], while in Emacs (my configuration) the format is [path][filename].
I would like my code to be usable regardless which of the two editors the text file is opened in. I guess I have to use some sort of an if-statement.
My pseudo code looks like this:
::uuu::
; find the window title of the opened txt file
WinGetTitle, windowTitle, A
; determine if text file is opened in Notepad3 or in Emacs
appName = <some function>
; construct file name and file path from window title
if appName = notepad3
fileName := SubStr(windowTitle,3,24)
filePath := SubStr(windowTitle,29,-12)
elseif appName = emacs
fileName := SubStr(windowTitle,-23)
filePath := SubStr(windowTitle,1,-24)
end
; send input to file
SendInput, %windowTitle% {enter}
SendInput, %fileName% {enter}
SendInput, %filePath% {enter}
return
1) what AHK function can be used to determine appName?
2) if appName can be determined, how should the if-statement in my code be made in correct AHK syntax?
I think I figured out one way to solve my own question:
::uuu::
; find the window title of the opened txt file
WinGetTitle, windowTitle, A
; find the process or app used to open the text file
WinGet, process, ProcessName, A
; construct file name and file path from window title
if (process = "Notepad3.exe")
{
fileName := SubStr(windowTitle,3,24)
filePath := SubStr(windowTitle,29,-12)
}
else if (process = "emacs.exe")
{
fileName := SubStr(windowTitle,-23)
filePath := SubStr(windowTitle,1,-24)
}
; send input to file
SendInput, %windowTitle% {enter}
SendInput, %fileName% {enter}
SendInput, %filePath% {enter}
SendInput, %process% {enter}
return
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'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:
{}
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.