I am beginner with autohotkey.
I wanted make script which checks if I write ":)" and then it replaces with this "😊" (emoji in web.whatsapp)
I dont know if it's possible to do using GetKeyState because in my keyboard I need Shift+dot for ":" and Shift+9 for ")".
I am sorry about my bad english. Hope you understand. :)
Thank you.
Code that works (thank Forivin)
:::)::
clipSave := ClipboardAll
Clipboard := "😊" ;
Send, ^v
Clipboard := clipSave
Return
:::D::
clipSave := ClipboardAll
Clipboard := "😂" ;
Send, ^v
Clipboard := clipSave
Return
This works for me:
:::)::
clipSave := ClipboardAll
Clipboard := "😊" ;make sure this actually contains the smiley character, once you copied that into your notepad application
Send, ^v
Clipboard := clipSave
Return
:::(::
clipSave := ClipboardAll
Clipboard := "😢" ;make sure this actually contains the smiley character, once you copied that into your notepad application
Send, ^v
Clipboard := clipSave
Return
Make sure to save your file with the correct encoding (UTF-8 did the job for me). You may wanna use something like Notepad++ for that.
It might also help to install the unicode version Autohotkey. (I use the latest 32bit Unicode version of AHK_L.)
What you are looking for is Hotstrings.
Example:
:::)::😊
Basically surrounding your statement with :: followed by what you want to replace it with.
Related
In an AHK script, I want to convert data I read from the clipboard earlier via ClipboardAll into a string I can manipulate, but StrGet() very oddly cannot do that.
!2:: clipget()
clipget()
{
clip := ClipboardAll
MsgBox % clip
MsgBox % NumGet(clip)
MsgBox % StrGet(clip)
Return
}
Firts MsgBox returns empty, because clip is not a string, as expected.
Second returns a numerical representation of the bit data, as expected.
The third returns nothing, not as expected.
I know I could just use clipstr = Clipboard in the first place to have it converted in the first place, but then I would have to read the clipboard twice as in:
clip := ClipboardAll
clipstr := Clipboard
to get both string data and bit data, but that looks uncool and takes longer if the data on the cliboard is large.
A dumb but functional way way could also be
Clipboard := clip
Sleep 500
clipstr := Clipboard
needless to say is not what I am looking for.
So, is there any way to get a string from ClipboardAll bit data with something like
clip := ClipboardAll
clipstr := MagicalFunction(clip)
?
Im not sure if this will help. But the clipboard is not the piece of string that is currently copied. The clipboard is a place where your computer holds your copied stuff, its a place where you can find your previous copied stuff.
A code I found in ahk's Clipboard doc is this
Loop, parse, clipboard, `n, `r
{
MsgBox, %A_LoopField% is your current copied first line..
}
I'm not very familiar with ahk's variable system but I think this should give a string output from %A_LoopField%
in AHK script: Save ClipBoardAll to File.
in external text editor: Write to the BEGINING of File some text eg. "rrr" (or you can do it by "copy +" in command line bat file)
in AHK script: Read File to variable.
I am writing a small AHK script that defines a few simple HotStrings.
The concept is that when I type "Build QA1", the appropriate text associated with that HotString appears.
No problem there ...quite simple ...the issue is that I wish to have the string associated with the HotString appear as part of the substitute text ...in the example below, the results should be
Build QA1
Now is the time for all good men
The script below accomplishes this and works fine ...it does exactly what I ask, HOWEVER, when I enter the HotString text and hit Enter or Tab or whatever initiates the HotString, that first line of text ( Build QA1 ) will "flash" on the screen as it is being substituted ...it makes it obvious that a HotString substitution is in operation ...
I would ideally like the HotString ( Build QA1 ) to remain as a part of the
substitute text without being replaced ...is this possible or is there a way to avoid the "flash" as that string is substituted ?
::Build QA1::
send, Build QA1
send, {enter}
send, Now is the time for all good men
return
Try it this way:
::b0::Build QA1:: ; automatic backspacing is not done to erase the abbreviation you type.
ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
clipboard := "" ; empty the clipboard (start off empty to allow ClipWait to detect when the new text has arrived
clipboard = ; copy this text:
(
Now is the time for all good men
)
ClipWait, 1 ; wait for the clipboard to contain data.
if (!ErrorLevel) ; if NOT ErrorLevel ClipWait found data on the clipboard
Send ^v ; paste the text
Sleep, 300 ; don't change clipboard while pasting! (Sleep > 0)
clipboard := ClipSaved ; restore original clipboard
VarSetCapacity(ClipSaved, 0) ; free the memory of the variable ClipSaved
return
See Hotstrings Options, Clipboard and ClipboardAll in the documentation.
I would like to print either « or » whenever I press Shift+Numpad7.
I know how to set up two different scripts: e.g. +Numpad7::« and +Numpad8::», but is there a way to have the output depend on whether the character before the caret is whitespace or not?
I.e., so I could type something like «Hello», where both times I pressed Shift+Numpad7
Shifting numpad numbers can have unintended overrides (like on my system) so I used Ctrl Numpad7, but YMMV:
^Numpad7::
oldClip := Clipboard ; save current clipboard
Send, +{Left}^c{right} ; select char to the left and copy to clipboard
ClipWait
lchar := Clipboard = " " ? "«" : "»" ; check if space or not
Send, %lchar% ; send lchar
clipboard := oldClip ; restore original clipboard
ClipWait
return
Btw, since unicode and ansi vers of AHK handle that character differently, on some systems you may get an extra preceding character in the output. Just change the last Send to:
Send, % SubStr(lchar, 0) ; send last character of lchar
And let us know what version worked for you.
I am quite new on AutoHotKey, and I'm trying to make my macro system. Currently I have a system that looks like this:
I have text variables
hi =
(
Hello,
Some more text
)
a Hotstring
::\hi::
Macro(hi)
return
And a function Macro:
Macro(text)
{
ClipSaved := ClipboardAll ; save clipboard
clipboard := text
ClipWait
Sleep, 150
Send, ^v
clipboard := ClipSaved ; restore original clipboard
return
}
The reason for using a function with clipboard is because long text blocks tend to have a delay until they are printed out, an issue that does not occur with the function.
I've found a concept called dynamic hotstrings, and I think I can somehow implement it so that I wouldn't have to write the second displayed block for every text field, but instead have a one hotstring that would understand that if it's my input starts with \ and there is a variable in the script under the name x that follows it, it should execute Macro(x), but I have never found any similar examples.
Could you provide me with a code sample or give any leads to what I should check out?
There are several dynamic Hotstring AutoHotkey functions, but this is probably the one you want to use Hotstring by menixator
So you need to download the hotstring.ahk and #include it as in the examples.
#SingleInstance, force
#include Hotstring.ahk
hi=
(
Hello,
Some more text
)
bye=
(
So long,
Some more text
)
Hotstring("/hi", "Paste")
Hotstring("/bye", "Paste")
return
Paste:
text:=Trim($,"/") ; we need to get rid of the leading /
text:=% %text% ; and need to dereference it
Macro(text)
Return
Macro(text)
{
ClipSaved := ClipboardAll ; save clipboard
Clipboard := text
ClipWait
Sleep, 150
Send, ^v
clipboard := ClipSaved ; restore original clipboard
return
}
There are some more elegant ways to do it, especially with the variables, you could store them in a global object (associative array) for example, but this should get you going.
The following AutoHotKey snippet is supposed to:
Verify if copied string is a number
If so, search for that number in a website and in Windows Search.
Nothing happens. The If's expression is not seeing integers and bypasses code.
Any ideas?
Send ^c
sss = ClipBoard
if sss is integer
{
Run, https://sd.borschow.com:8443/SREdit.jsp?id=%sss%
Run, search-ms:query=%sss%
}
A text copy usually isn't as fast as AHK executes the subsequent code. That is, you need to wait for the clipboard to be updated:
F9::
oldClip := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait
clip := Clipboard
if clip is integer
{
msgbox, integer
}
else
{
msgbox, not an integer
}
Clipboard := oldClip
; we better make that empty, since it could contain sensitive data
oldClip := ""
return
Best practice is to store the clipboard, empty it, trigger the copy, and wait for the clipboard to contain something. And finally, restore the old clipboard if you don't need the contents anymore.