Jump to content

Keyboard macros


Recommended Posts

I tried looking at the help files and around the forum but couldnt find what i needed, also this should be pretty simple.

This might seem like a weird request.

When i press 'a' on my keyboard i need it to press 'a' followed by 'b' automatically.

So that whenever i press 'a' it activates 'b' after 'a'.

I tried using python but i'm not good enough.

I'm trying this to make it easier to fill out certain information in spreadsheets.

Thanks in advance,

Bas

Edited by basgen
Link to comment
Share on other sites

There are a couple ways that i know of. One being hotkeyset and the other is _IsPressed.

HotKeySet("a", "some_function_name")

while 1

your loop or what ever your doing

wend

func some_function_name()

send("a")

sleep(10)

send("b")

sleep(10)

endfunc

is prob the easiest way. good luck!

Link to comment
Share on other sites

  • Moderators

MasonMill,

Have you tried your code? I think not, because as it stands you enter an infinite loop. :

As you Send the "a", you trigger the HotKey again, which Sends another "a", triggering the HotKey yet again, which........ :P

Your function needs to unset and then reset the HotKey - like this: :blink:

Func some_function_name()
    
    ; Unset the HotKey
    HotKeySet("a")
    ; Send the keys
    Send("a")
    Sleep(10)
    Send("b")
    Sleep(10)
    ; Reset the HotKey
    HotKeySet("a", "some_function_name")
    
EndFunc

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Let me see if i understand it right.

You made the hotkey 'a' so that every time i press the key 'a' it starts the function?

Then the function sends 'a', sleeps (is that 10s or 10 ticks or 10ms?), then sends 'b'

Then it stops.

Does it need to loop?

I tried running that script but it doesnt seem to do anything, could be me tho.

Sorry for not understanding, i'm guessing this is c++ based or something... to which i am clueless :blink:.

Link to comment
Share on other sites

Let me see if i understand it right.

You made the hotkey 'a' so that every time i press the key 'a' it starts the function?

Then the function sends 'a', sleeps (is that 10s or 10 ticks or 10ms?), then sends 'b'

Then it stops.

Does it need to loop?

I tried running that script but it doesnt seem to do anything, could be me tho.

Sorry for not understanding, i'm guessing this is c++ based or something... to which i am clueless :blink:.

I couldnt edit my last post sorry.

I tried

------------------

HotKeySet( "a", "foobar" )

Func foobar( )

Send( "a" )

Send( "b" )

Endfunc

While 1

Sleep( 1 )

WEnd

-----------------

instead.

The thing is with your script is that if i run it, it closes right away.

Mine stays running but doesnt really work ;)

Link to comment
Share on other sites

  • Moderators

basgen,

A slightly belated welcome to the AutoIt forum. :blink:

You will be able to edit your posts after the next one. :P

Did you see my explanation above? It explains why nothing happens and you do not exit when you run MasonMill's code.

Try running this:

; Set the HotKeys
HotKeySet("a", "_ab")
HotKeySet("{ESC}", "On_Exit")

; Now keep the script active
While 1
    Sleep(10)
WEnd

Func _ab()

    ; Unset the HotKey
    HotKeySet("a")
    ; Send the keys
    Send("a")
    Sleep(10)
    Send("b")
    Sleep(10)
    ; Reset the HotKey
    HotKeySet("a", "_ab")

EndFunc

Func On_Exit()
    Exit
EndFunc

Please ask if you have any questions. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Apparently its rude to PM people for help, so sorry :blink:

Is there a way that i can make it so i can only use the script once ever like second, now if i hold tab for a little too long it spams... its not

a big problem but my key sensitivity is pretty high so its a little annoying if it repeats too fast.

I tried changing the :

While 1

Sleep(10)

WEnd

but maybe its not possible? since it jst registers every time i press tab.

Link to comment
Share on other sites

  • Moderators

basgen,

Apology accepted! ;)

Try increasing the Sleep time just before you reset the HotKey in the function. That way the HotKey is not reset and so you cannot spam it.

You will, of course, still get the typematic repeats of the the basic key! :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...