Content

ramblings of a coldfusion developer

Autohotkey Week: Day 3 – Clipboard

Wednesday 19 August 2009 - Filed under Code

So now we have Autohotkey installed and have learned to do some basic text manipulation.  Next we will explore how we can use Autohotkey to manipulate existing text by using the clipboard.

Remember in our previous example how we used Autohotkey to go UP and LEFT to position our cursor?  Since Autohotkey can press keys for us, there is no reason why it can’t press CTRL+C for us!  Here is one I use all the time – the classic CFDUMP:

F1::
clipboard =
send ^c
clipwait, 1
If ErrorLevel = 0
{
clipboard = <!--- TODO - for debugging -->`n`n
send ^v
}
return

We are getting a bit more complicated but I think you should be able to follow along.  I’ve got this setup to fire when I hit F1 (you of course can select any key). BUT I first have to select something or there will be nothing to copy!  So select something, hit F1 and it does a send ^c which is the Autohotkey syntax for ‘press CTRL+C‘.  It waits a sec, checks for errors and then writes out a new string to the clipboard and pops in the text we first selected  %clipboard% and outputs a nice string with our variable wrapped up:

<!— TODO – for debugging —>
<cfdump var=”#myVariable#” top=5 label=”My Dump”>
<cfabort>

Here is another great use. I’m working on an old project with no queryparams.  Ugh!  So I wrote this shortcut to grab a variable from a query, strip out the single quotes (if they exist) and wrap it with a variable.  I’ve got a few of these defined so I can output a varchar or numeric depending on my shortcut.

!q::
clipboard =
send ^c
clipwait, 1
If ErrorLevel = 0
StringReplace, clipboard, clipboard, ', , All
{
clipboard =
send ^v
}
return

I have several more of these setup to do UCase(), Upper(), Trim(), etc. All by simply modifying the clipboard.  Hopefully by now you are seeing the power of Autohotkey!  Tomorrow we’ll explore how you can use it to fire off programs.

Tagged: »

2009-08-19  »  Jim Priest

Share your thoughts

Re: Autohotkey Week: Day 3 – Clipboard







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>