Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Cursors in Autohotkey

Is there any way in Autohotkey to mimic multiple cursors like in sublime. I need a hotkey that sends and couple of text lines and leaves me with multiple cursors so I don't have to type the same text over and over. Like in the gif below.

Thanks xD.

Sublime multiple cursors

like image 408
IGRACH Avatar asked Nov 24 '16 22:11

IGRACH


2 Answers

I need a hotkey that sends and couple of text lines and leaves me with multiple cursors so I don't have to type the same text over and over.

Just to open Sublime Text and type the text you need to.

and leaves me with multiple cursors

You cannot just put several cursors/carets on any application. The application must to provide support for multiple cursors creation. AutoHotKey is not a magic application which becomes everything possible, it is an automation application to automate boring or repeated tasks. Nevertheless, maybe you can search if there are some application, which can hijack other applications to compel them to use multiple cursors/carets.

However, if you are interested in make the AutoHotKey application to create several cursors on Sublime Text, you can write an AHK script to automate the cursors creation on Sublime Text using the Sublime Text keyboard shortcuts. The default Sublime Text API for Multiple cursors/carets is not very rich by keyboard, but there are Packages/Plugins as Power Cursors and Column-Select you can install on Sublime Text to improve it.

Personally I think you are better off writing a Sublime Text Package/Plugin with the Sublime Text API to create the multiple cursors/carets you want to, instead of externally to perform it with an AHK script by keyboard shortcuts.


Ultimately you can write a AHK script which asks a text and type it for you on several lines. For example:

  1. If you enter Type This,5
  2. The script could type on the current window caret/cursor position
  3. To go back with the caret 9 positions.
  4. To go one line down by pressing the down key.
  5. To type again the same text.
  6. Repeate this process until 5 times.

However with this we may easily see down sides as when there are empty lines as on your screen animation. So you would be better off just using Sublime Text, which is in my Opinion the best software that exists from the all as Notepad++, Atom, etc. Sadly it is closed source, so you cannot improve it by yourself or know why it is crashing certain times, which makes me wonder to write a new one open source, compatible with the current plugins and settings for it.

like image 158
user Avatar answered Oct 14 '22 12:10

user


As others have mentioned, you cannot use true multiple cursors unless the program your're using supports it - however, you could attempt to emulate multiple cursors in the following way:

  1. Build a defined list of cursor positions relative to the user's cursor (e.g. 2 lines down, 3 chars across, etc.). Must be relative! How you build this list is up to you.
  2. Wait for the user to press a key
  3. Once input is complete, move the physical cursor to the relative positions in sequence and repeat the keypress from step 2. This should be fast so the user doesn't notice the cursor jumping around.
  4. Move the cursor back to where the user had it and go to step 2.

This is essentially how Sublime Text implements multiple cursors, but it has much better support (and speed) because it is software-level. This solution is input-level and will probably be unable to display where the multicursors actually are, will be slow, etc. Also, because it requires a fair bit of positional calculation, the implementation may complex and prone to bugs.

Sorry - this is the best I've got, it's definitely a hack - probably better (simpler) to just automate a copy and paste :P

like image 1
Jason Cemra Avatar answered Oct 14 '22 12:10

Jason Cemra