Jump to content

keystroke macro question


Recommended Posts

I want to create some keystroke macros to use in text editors. The following was intended to insert three spaces at the start of the line, but it did not appear to do anything; suggestions?

;define keystroke macros similar to those used in nedit

While 1; Permanently loops

Sleep(100)

Wend

global $r_arrow=chr(62)

HotKeySet("^+&r_arrow","tab_ins")

Func tab_ins()

Send("{HOME}")

Send("{SPACE 3}")

HotKeySet("^+&r_arrow")

EndFunc

Link to comment
Share on other sites

You're trying to use your variables in quotes, everything in quotes is plain text.

This is how it should be:

;define keystroke macros similar to those used in nedit
While 1; Permanently loops
Sleep(100)
Wend

global $r_arrow=chr(62)

HotKeySet("^"&$r_arrow,"tab_ins")

Func tab_ins()
Send("{HOME}")
Send("{SPACE 3}")
HotKeySet("^"&$r_arrow)
EndFunc

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

That hotkey will never set because it is defined after the while loop is the hotkey you want CTRL SHIFT RIGHT? because that is what I have done below!

global $r_arrow=chr(62)

HotKeySet("^+{RIGHT}","tab_ins")

While 1; Permanently loops
    Sleep(100)
Wend

Func tab_ins()
    ConsoleWrite("CTRL SHIFT RIGHT Hotkey was pressed" & @crlf);debug to Scite Console
    Send("{HOME}")
    Send("{SPACE 3}")
EndFunc
Link to comment
Share on other sites

That hotkey will never set because it is defined after the while loop is the hotkey you want CTRL SHIFT RIGHT? because that is what I have done below!

Ooops I missed that one :)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

That hotkey will never set because it is defined after the while loop is the hotkey you want CTRL SHIFT RIGHT? because that is what I have done below!

global $r_arrow=chr(62)

HotKeySet("^+{RIGHT}","tab_ins")

While 1; Permanently loops
    Sleep(100)
Wend

Func tab_ins()
    ConsoleWrite("CTRL SHIFT RIGHT Hotkey was pressed" & @crlf);debug to Scite Console
    Send("{HOME}")
    Send("{SPACE 3}")
EndFunc

Thanks for you help, but I am still confused. I used your version verbatim, compiled and started the executable. When I hit CTRL SHIFT RIGHT some very bizarre stuff happens. First, it is as if I hit CTRL SHIFT HOME because the text from cursor position to start of document is all highlighted. But clicking on the document does not clear the selection, rather the selection boundary jumps from the document start to where I click. And all key mapping is SNAFU'd until I killl the process. What's going on?

Link to comment
Share on other sites

Thanks for you help, but I am still confused. I used your version verbatim, compiled and started the executable. When I hit CTRL SHIFT RIGHT some very bizarre stuff happens. First, it is as if I hit CTRL SHIFT HOME because the text from cursor position to start of document is all highlighted. But clicking on the document does not clear the selection, rather the selection boundary jumps from the document start to where I click. And all key mapping is SNAFU'd until I killl the process. What's going on?

To be fair it's not a particularly brilliant use of Hotkeys

First, it is as if I hit CTRL SHIFT HOME

Well you are actually holding down CTRL and SHIFT and then the function sends "{Home}" so that's not really supprising

Maybe as a start you should try adding the send functions to a different key and work on more complex combinations later once you know the functions are doing what is required.

Perhaps you could try sending Shift up and CTRL UP before sending {home} Space 3 if you particularly want to use the keys you specified earlier.

What text editor(s) are you trying to use this with?

Link to comment
Share on other sites

In Scite this will go to the beginning of the current line that the cursor is on and insert 3 spaces

global $r_arrow=chr(62)

HotKeySet("^+{RIGHT}","tab_ins")

While 1; Permanently loops
    Sleep(100)
Wend

Func tab_ins()
    ConsoleWrite("CTRL SHIFT RIGHT Hotkey was pressed" & @crlf)
    Send ("{ShiftUP}")
    Send ("{CTRLUP}")
    Send("{HOME}")
    Send("{SPACE 3}")
EndFunc
Link to comment
Share on other sites

To be fair it's not a particularly brilliant use of Hotkeys

Well you are actually holding down CTRL and SHIFT and then the function sends "{Home}" so that's not really supprising

Maybe as a start you should try adding the send functions to a different key and work on more complex combinations later once you know the functions are doing what is required.

Perhaps you could try sending Shift up and CTRL UP before sending {home} Space 3 if you particularly want to use the keys you specified earlier.

What text editor(s) are you trying to use this with?

I work primarily in linux, using nedit. Therein I have numerous macros (aka hotkeys) to indent/de-indent text by three spaces, comment/uncomment, etc., each time ending in a down key.

I am now working on Satellite Forms, which has a scripting function with a very basic editing window, and I would like to set up same hotkeys to do the same.

I have been testing autoit in notepad and write.

I tried your code in your 9:51 post but still got weird results (in write it seemed to go to the document start and replace the first 3 chars w/ spaces*, after which key mapping was fubared.

I'll try your suggestion above, see if I can get back to my goal of hitting CTRL > (aka CTRL SHIFT .), then move forward the resulting actions.

Thanks again.

Link to comment
Share on other sites

My code in post #7 works fine with Write, Notepad and Scite

assuming I have it correct for what you are trying to do it goes to the beginning of the line which the cursor is currently active and inserts 3 spaces

Link to comment
Share on other sites

Ahh. You are using the LEFT control and shift. I was using, as I always do, the right control and shift, which fubar everything. I tried to use {RCTRL}{RSHIFT} in lieu of ^+ in the hotkey call, but no change. Is there any way to make ^ imply either left or right control key, rather than left only?

Thanks for your patience.

Link to comment
Share on other sites

Ahh. You are using the LEFT control and shift. I was using, as I always do, the right control and shift, which fubar everything. I tried to use {RCTRL}{RSHIFT} in lieu of ^+ in the hotkey call, but no change. Is there any way to make ^ imply either left or right control key, rather than left only?

Thanks for your patience.

I'm not sure you can use those keys as according to the helpfile they are "modifier keys"

I tried doing it this way which did call the function but because RSHIFT and RCTRL were pressed it had undesired results which highlighted the text and send the cursor to the top of the page this then left one of the keys pressed down.

#include <misc.au3>

While 1
    _checkKeys()
    Sleep(100)
WEnd


Func _checkKeys()
If _IsPressed("27") and _IsPressed("A1") and _IsPressed("A3") then tab_ins()
EndFunc

Func tab_ins()
    ConsoleWrite("CTRL SHIFT RIGHT Hotkey was pressed" & @crlf)
    Send("{HOME}")
    Send("{SPACE 3}")
EndFunc

Maybe someone has a better idea

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...