Art Ianuzzi
Art Ianuzzi

Reputation: 307

Moving cursor with AutoKey script

Is it possible to write an AutoKey script to insert a string and then move the cursor to a position within the imported script? For example, I would like a script that inserts console.log(); and then moves the cursor so that it it between the parentheses.

Also, are there any code references for writing scripts for AutoKey, all I've been able to locate are about a dozen example scripts.

Upvotes: 3

Views: 1618

Answers (2)

Omri Caspi
Omri Caspi

Reputation: 31

In autokey-gtk 0.90.4 and later (Don't know about older versions), you can insert "<cursor>" where you want to position the cursor.

So for example, in your case:

console.log(<cursor>);

Upvotes: 3

hardcase
hardcase

Reputation: 1

It would be easier to create a Phrase instead of a python script.

After you create a New Phrase and give it a name, then place the following in the "Enter phrase contents" box on the top right of the autokey window:

console.log();

Then set your hotkey or abbreviation and specify a window filter if you only want it to work in a single window.

If you want to use an abbreviation, but can't get them to work, then this HowTo will help a lot:

Click on the folder you want to put the abbreviation in, then click on the toolbar menu item "New" and select Phrase. Give it a name (this has nothing to do with the abreviation trigger or what you want change the abbreviation to).

Highlight the entry you just created and in the bottom of the right panel click on the "Set" button accros from the "Abbreviations: (Non configured)" text on the left.

In the popup window click on the Add button.and type the abbreviation you want to use int the text box that appeared when you clicked on Add. IMMEDIATLY CLICK ON THE WHITE AREA THAT THE TEXT BOX WITH YOUR ABBREVIATION IS IN--NOT IN THE TEXT BOX!

Then click on the OK button and save either with Ctrl S or the Save button on the menu bar. You will not see your abbreviation until you do this.

Next, click on the right side window and highlight or delete "Enter phrase contents" and type in what you want the abbreviation to turn into. Then uncheck (click in the box to the left) the "Always prompt before pasting this phrase".

After that, save either with Ctrl S or the Save button on the menu bar.

At this point your abbreviation should work for you.

Of the 49 possible ways to try and enter and activate an abbreviation this is the only one that I found that would work. Note, you have to follow it EXACTLY...

The above all assumes you are using the original version of Autokey not the py3 version.

Upvotes: -1

Related Questions