Jump to content
cag8f

How to create simple keyboard shortcut to insert custom text?

Recommended Posts

cag8f

Hi all.  I want to create a simple keyboard shortcut that automatically pastes a small amount of custom text.  But when I execute the assigned shortcut, nothing occurs.  Specifically, here's what I did.

I created an AutoIt script which contains one line:

Send("my custom text");

I then compiled this script into an EXE, sent it to my desktop as a shortcut, and assigned a keyboard shortcut to that shortcut (ctrl + alt + q).  But when I tested it, nothing happened.  Specifically, I opened Notepad then executed the keyboard shortcut.  After about 1-2 seconds, the Notepad window deselected, then nothing else happened.  Thoughts on what I'm doing wrong?

Thanks in advance.

Share this post


Link to post
Share on other sites
JLogan3o13

@cag8f why not just use HotKeySet, and run the compiled executable as a try app? This works just fine for me:

HotKeySet("{F11}", "SendMe")

While 1
    Sleep(100)
WEnd

Func SendMe()
    Send("my custom text")
EndFunc

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
careca
Posted (edited)

When you start something by that method, you lose focus on the active window, i couldn't find a workaround that.

Maybe, in theory, you could retrieve the Z order of the windows and activate the higher one before the send.

Try:

MouseClick("primary")
Send("my custom text")

Not elegant, but worked here, just have to keep the mouse in the window you want to paste.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
cag8f

@JLogan3o13  Thanks for that.  But what do you mean by "run the compiled executable as a try app?"

@careca  OK thanks, that worked.  It's unfortunately a *tad* slow.  The text I want to insert is fairly short (~25 characters).  So I can type it relatively quickly--as quick as the keyboard shortcut inserts it.  I was hoping a shortcut would be able to do so much faster.  Is there perhaps some setting or parameter I'm missing?

Share this post


Link to post
Share on other sites
pixelsearch

@cag8f : if you want the text to be written really fast, you have to change 2 options, as shown in this code :

Opt("SendKeyDelay", 0) ; 0 removes completely the delay
Opt("SendKeyDownDelay", 0) ; 0 removes completely the delay
HotKeySet("{F11}", "SendMe")

While 1
    Sleep(100)
WEnd

Func SendMe()
   HotKeySet("{F11}") ; deactivate the hotkey in case the user presses it too long
   Send("my custom text")
   HotKeySet("{F11}", "SendMe") ; reactivate it
EndFunc

I tested it with Send() of 1000 characters, it took 2 seconds on my antique PC, then compared these 1000 characters to the originals, there were exactly the same.

JLogan3o13 means that you have to double clic on the .exe, then its icon shows in the Systray and the program runs constantly in the background (because of the While WEnd loop that will never end) so you will able to press the F11 key in any window you like. When you're done, right clic on the systray icon, choose "exit" and the program will end. Good luck.
 

Share this post


Link to post
Share on other sites
cag8f

@pixelsearch OK thanks very much for all that.  I gave your code a try, and it worked just as you and @JLogan3o13 described.  I have a couple follow-up questions:

>> When you're done, right clic on the systray icon, choose "exit" and the program will end. 

Is there an actual need/benefit to doing this?  I'd prefer it if I could simply shut down Windows.  I gave it a test, and Windows shut down without complaining.  But is this disadvantageous for any reason?

Do you see any issue with placing the EXE in my startup folder, so I don't have to manually run it every time?

Thanks!  

 

Share this post


Link to post
Share on other sites
careca

No problem, windows will close all processes.

Yes you can put it in startup.

I thought you didn't want another program running in background.

Did you take a look at the programs that paste text in the download section?

Instead of just one line, you could have multiple shortcuts and lines.

Not trying to promote my program at all, just trying to show you what's available.

;)


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
cag8f
Posted (edited)

@careca

>> I thought you didn't want another program running in background.

DId I say that?  I don't recall saying that.  If so, I didn't mean it.  Another program in the background should be OK in this case.

>> Did you take a look at the programs that paste text in the download section?

No I didn't.  Where are they?  Can you send a link to those programs.

>> Instead of just one line, you could have multiple shortcuts and lines.

This actually sounds like something I might want.

 

Edited by cag8f

Share this post


Link to post
Share on other sites
ViciousXUSMC

JLogans answer is pretty much the standard for how to do this.

The other thing I like ALOT so that I do not need to remember obscure hotkeys is HotStrings

 

This lets you just come up with a word phrase.

As an IT guy say I had a big block of text I send all the time as a generic reply to resetting a password.

I can set a string like ";passwordreset" and type that and have it replaced with my block o' text

Strings can be short and easy to remember.

 

#Include <hotstring.au3>

HotStringSet(";passwordreset", "_resetpassword")

While 1
    Sleep(10)
WEnd

Func _resetpassword()
    Send("{Backspace 14}Your password has been reset to _____ please login within the next 24 hours to set a new password or your account will get locked again and you will need to put a new ticket in for a new password reset request")
EndFunc

 

Share this post


Link to post
Share on other sites
cag8f

@ViciousXUSMC OK thanks for that.  I can't think of any uses for hotstrings now, but I'll keep it in-mind.

Share this post


Link to post
Share on other sites
careca

A similar take on that.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
cag8f

@careca Got it, thanks--I"ll look into it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×