Place text from inputbox in a string - autohotkey

I'm looking for a ahk script to do the following:
Show popup box
Enter text
Show standardtext + string in popup box.
So that when for example I press #r i get a popup box, i type in Marc and I get
"dear regards Marc".
So in Java it would be be something like
var1 = inputBox("whats your name")
var NameRegards = function(text){
"dear regards" + var1
}
show NameRegards
Anybody a clue how I can manage this in ahk?

How about doing it exactly as you described?
InputBox, varName, Name input, What's your name?
MsgBox , , Output, Dear regards %varName%
Works fine for me.

Here is an untested start..
#SingleInstance Force
#Persistent
Return ; Stop the startup lines otherwise #r will run on startup...
#r:: ; [Win]+r to start this script
InputBox, MyName, This is your Windows Title, Type your name:
SendInput, Dear regards`, %MyName% ; Using `(On ~ key on US KB) to literally print a comma
; SendInput, % "Dear regards, " MyName ; Alternative way
Return

Related

I‘m not able to put an variable value as another variable‘s value in ahk

I want to make an time recorder. What I know is not enough.
I want to make an thing that will show up an msgbox if i press ctrl + alt + pgdn, asking to record the time. If I click on "yes", I get
another msgbox saying the time is recorded. after i close the msgbox, the current time would get recorded as an variable. If I press ctrl + alt + enter, the recorded time will get printed in an msgbox.
you can make changes to this code:
<!<^PgDn::
MsgBox, 4,Record time,Do you want to record the time?
If MsgBox Yes{
timestamp := %A Hour% ;below, the error is written about this line
timestamp2 := %A Min%
MsgBox time recorded.
}
else{}
return
<^<!enter::MsgBox time: %timestamp%:%timestamp2%
With this, there is an strange error saying "%A:this parameter has an variable missing it‘s ending percent sign"
How do I fix this problem? Any answers? Thanks.
Variable names in an expression are not enclosed in percent signs.
A_Hour and A_Min are Built-in Variables
<!<^PgDn::
MsgBox, 4,Record time,Do you want to record the time?
IfMsgBox Yes ; not "If MsgBox Yes"
{
timestamp := A_Hour ; expression
timestamp2 := A_Min
MsgBox time recorded.
}
; else{
; do sth else
; }
return
<^<!enter:: MsgBox, time: %timestamp%:%timestamp2% ; this is a command (no expression)

How do I escape the '+' characters in an AutoHotKey, with the date script?

I use AutoHotKey to display actual date.
here is the code :
:*C:]d:: ; This hotstring replaces "]d" with the current date and time via the commands below.
FormatTime, CurrentDateTime,, yyyy‑MM‑dd ‒ HH'H'mm '(UTC+1)' ; It will look like 2005-01-09 15H53 (UTC+1)
SendInput %CurrentDateTime%
return
But the result miss the '+', I used "`" or "",
both not vrog.
Thank pro help.
Good day and long and happy life.
Use the text send mode.
:*C:]d:: ; This hotstring replaces "]d" with the current date and time via the commands below.
FormatTime, CurrentDateTime,, yyyy‑MM‑dd ‒ HH'H'mm '(UTC+1)' ; It will look like 2005-01-09 15H53 (UTC+1)
SendInput, {Text}%CurrentDateTime%
return
Also, if you'd want to ditch the legacy AHK syntax, you'd do this:
:*C:]d::
FormatTime, CurrentDateTime, , % "yyyy‑MM‑dd ‒ HH'H'mm '(UTC+1)'"
SendInput, % "{Text}" CurrentDateTime
return

How can I use Autokey to grab highlighted text + url and then insert said highlighted text + url in the placeholders of a phrase?

I'm trying to get Autokey to work like Autohotkey worked for me in Windows.
One very useful function that was possible to set up in Autohotkey was assigning a keyboard key to grab highlighted text, then go to url, grab that url, and then insert the highlighted text and URL in specific places within a predetermined phrase.
It was extremely useful to create text with links in different formats.
The Autohotkey script for what I'm describing looked something like this:
insert::
clipboard =
Send, ^c
ClipWait
myText = %clipboard%
Send, !d
clipboard =
Send, ^c
ClipWait
myURL = %clipboard%
myLink = %myText%
clipboard = %myLink%
return
Is there a way to translate that into a working Autokey script?
# assigning a keyboard key to
# `hotkey - a key or combination of keys that, when pressed, will trigger AutoKey to do something; run a script, insert a phrase or display a menu. A hotkey can be created using any key on the keyboard (within reason), with or without one or more modifier keys. The modifier keys are Shift, Control, Alt and Super (a.k.a. Windows).`
# [Guide](https://github.com/autokey/autokey/wiki/Beginners-Guide)
import os, time
# grab highlighted text
myText = clipboard.get_selection()
# then go to url
myCmd = "/usr/bin/firefox --new-window http://www. your site .biz/"
os.system(myCmd)
time.sleep(0.25)
# grab that url, and then
keyboard.send_keys('<F6>')
time.sleep(0.25)
myURL = clipboard.get_selection()
# insert the highlighted text and URL in specific places within a predetermined phrase.
# run a window wait, then paste the texts there. Following example opens a msgbox2sec.ahk (create it first):
myCmd = 'wine ~/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe /home/administrator/Desktop/msgbox2sec.ahk'
os.system(myCmd)
time.sleep(0.25)
active_class = window.get_active_class()
if not active_class == "your class name": # for example: "autokey-gtk.Autokey-gtk":
time.sleep(0.25) # sleep longer
myLink = "" + myText + ""
# paste your link, then copy it:
keyboard.send_keys(myLink)
# select select a line:
keyboard.send_keys('<home>')
keyboard.send_keys("<shift>+<end>")
# copy line to clipboard:
keyboard.send_keys('<ctrl>+c')
# or copy line to variable:
c = clipboard.get_selection()

How to pass window title to user function in AutoHotKey

I want to pass the window title into a function I wrote in AutoHotKey, is window title WinTitle a string? I have 4 window titles, and I need to pass them to the same function.
Extract(my_window_title) {
; Wake and select the correct window to be in focus
WinWait, my_window_title,
IfWinNotActive, my_window_title, , WinActivate, my_window_title,
WinWaitActive, my_window_title,
; ... do a bunch of things
}
I call the function like this
title1 = "Some title"
Extract(title1)
and I also tried putting % in all the variables
Yes WinTitle is basically a string.
Check out your Autohotkey-folder, there should be a file called "AU3_Spy.exe". Use it to find the window titles.
And as Elliot DeNolf already mentioned, you made some mistakes with variables. You should also take another look at the syntax of IfWInNotActive.
This should work:
Extract(my_window_title) {
; Wake and select the correct window to be in focus
WinWait, %my_window_title%
IfWinNotActive, %my_window_title%
{
WinActivate, %my_window_title%
WinWaitActive, %my_window_title%
}
msgbox, %my_window_title%
; ... do a bunch of things
}
title1 = MyWindowTitle
Extract(title1) ;functions always expect variables, no percent-signs here
There are a few things that look like they are causing an issue in your script.
When assigning a string value and using =, quotes are not needed. If you assign the value using :=, then you need the quotes. These 2 lines are equivalent:
title1 := "Some Title"
title1 = Some Title
Once these values are called via a function ie. Extract(title1), % symbols must be used (as you mentioned at the end of your question). This can be called in 2 ways:
WinActivate, %my_window_title%
WinActivate, % my_window_title
If the title is invalid, your script will wait indefinitely on WinWait and WinWaitActive. I would recommend using a timeout value and then checking ErrorLevel to see if it was successful or not.

How to get the active window's title with AutoHotKey?

I wrote this short test code, but it didn't work. What am I doing wrong?
F12::
WinGetTitle, Title, A ;
MsgBox, "%Title%"
The displayed result was ""
I removed a ; and added return and this worked...
F12::
WinGetTitle, title, A
MsgBox, "%title%"
return
The best practice would probably be to use WinGetActiveTitle:
F12::
WinGetActiveTitle, Title
MsgBox, The active window is "%Title%".
return
If you do not put in a return it will run down your whole file.
Probably something not running through later in it.
Don't think the ; will affect it.
Anything after a ; is omitted from code as a comment.
Using WinGetActiveTitle or WinGetTitle will do.
Note the output of WinGetTitle contains more than the window title.
You might want to remove the ending part with the program name e.g." - Google Chrome".
WinGetActiveTitle, Title
StringGetPos,pos,Title,%A_space%-,R
if (pos != -1)
Title := SubStr(Title,1,pos)
In AutoHotKey 2 you can use this:
title := WinGetTitle("A") ; "A" matches "Active" window
In AutoHotKey 1 you can use:
WinGetActiveTitle, title