topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 9:50 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Beginner Autohotkey question(s)  (Read 5495 times)

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Beginner Autohotkey question(s)
« on: November 22, 2007, 08:15 AM »
...because where else would I go? :)

1. I am using AHK only for text expansion (hotstrings) right now. Is there a way to add hotstrings to the automatically executed script and have them picked up without manually clicking "Reload" in the tray icon? It would be perfect if AHK were monitoring the script file for changes, I suppose.
[Edit] Never mind, I've found the Edit and Reload commands. Now if only I could tell the Edit command to open the script in TextPad instead of Notepad...

2. Is there a way to trigger a hotstring (or another similar feature) using selected text, rather than typing? E.g. when I encounter a term in a document I am translating, I would like to select the text and have it replaced with a translation, defined in AHK script. (For example, with hotstrings I have to type "Control Panel" to get the translation. I would like to select "Control Panel" instead, press a key and have the translation pasted in.)

Thanks!
.marek
« Last Edit: November 22, 2007, 11:33 AM by tranglos »

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: Beginner Autohotkey question(s)
« Reply #1 on: November 22, 2007, 06:54 PM »
hi marek,

this is how i will do, for the 1st q:
you can either associate .AHK with TextPad with the registry (see the example)

REGEDIT4

[HKEY_CLASSES_ROOT\.ahk]
@="AutoHotkeyScript"

;Set notepad as the default AutoHotkey editor
[HKEY_CLASSES_ROOT\.ahk\shell\Edit]
@="Edit"

[HKEY_CLASSES_ROOT\.ahk\shell\Edit\command]
@="C:\\WINDOWS\\System32\\notepad.exe \"%1\""

or use the "Run" command like this:
Run, <edit program> "%A_ScriptFullPath%"

2nd q:
you can use SetTimer to monitor if there are any selected text and run a routine from there but normally AHK requires a keyboard or mouse intervention to trigger an action. and also have a look at this script as an example:

Tool tip dictionary


tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: Beginner Autohotkey question(s)
« Reply #2 on: November 22, 2007, 07:03 PM »
hi marek,
this is how i will do, for the 1st q:

Thanks!

you can use SetTimer to monitor if there are any selected text and run a routine from there but normally AHK requires a keyboard or mouse intervention to trigger an action. and also have a look at this script as an example:

Oh, I do want to trigger this manually. I may not have explained it fully. Standard hotstring operation is that you type "btw", and ahk gives you "By the way", as it is monitoring your keypresses. I would like to be able to select the text "btw", press a hotkey, and get "By the way". So the difference is I would not be typing b-t-w myself, since it's already in the document.

Since the operation could go via clipboard (as a last resort, but I could live with that), and I can assign clipboard contents to a variable, the only thing I'm missing is the ability to tell Ahk, in a script, to "expand this variable as if it were a hotstring I've just typed".

marek

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Re: Beginner Autohotkey question(s)
« Reply #3 on: November 22, 2007, 09:38 PM »
Oh, I do want to trigger this manually. I may not have explained it fully. Standard hotstring operation is that you type "btw", and ahk gives you "By the way", as it is monitoring your keypresses. I would like to be able to select the text "btw", press a hotkey, and get "By the way". So the difference is I would not be typing b-t-w myself, since it's already in the document.

Since the operation could go via clipboard (as a last resort, but I could live with that), and I can assign clipboard contents to a variable, the only thing I'm missing is the ability to tell Ahk, in a script, to "expand this variable as if it were a hotstring I've just typed".

marek

ok, i see now.. this would be useful in a "spell-checker" mode, normally in this case, as you mentioned AHK would store the selected text in the clipboard variable and use an array containing an existing list to check against.. it didn't occur to me before & now i'm also looking forward to a solution this other than the clipboard method. :)

here is a link to the Hotstrings and Auto-replace documentation..