Sign in to follow this  
Followers 0
FredX

Send-command printing more then 1 letter ?

14 posts in this topic

I would like to make life easier with the hotkeyset-function and the Send-function. Means: Instead of writing sentences or words pressing a key.

Goal is to have a macro with 3 or 4 hotkeys that print out a word when pressing them.

Now i'm not a good programmer i tried with google and some parts of Autoit3-macros i found in the net but what i managed was printing out a letter but not the whole word.

All i have(stolen from this forum) so far is:

 
 
 
Hotkeyset ("{A}", "A")
 
While 1
 Sleep (1000) ;Keeps script running
Wend
 
Func A()
Send("{Liebe Mitbewohner und Nachbarn,}")
 
Endfunc

When i run this macro and press shift+a, it just prints the "L" but not the rest.

I saw other macros with this function and more then one letters to be posted but they used for every letter a send-command, and this would be a big macro then, isn't there a better solution ?

And if this macro is working, can i just put it several times into the script to have several hotkeys programmed ?

 

Share this post


Link to post
Share on other sites



Are you serious ?

Share this post


Link to post
Share on other sites

FredX,

Welcome to the AutoIt forums. :)

Your syntax is not quite right:

HotKeySet("a", "_A") ; Help file suggests using lower case letters

While 1
    Sleep(10) ;Keeps script running - 10ms will suffice
WEnd

Func _A()
    Send("Liebe Mitbewohner und Nachbarn,")
EndFunc   ;==>_A
Note the lack of surrounding braces ({ }) in both the HotKey definition and the Send function. They are only required in the definition when you need to define a special key (e.g. {ENTER}) and when used inside the Send function limit the characters sent to the first alone - as you have found. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thank you for the welcome. I actually had a spooky experience: I tried out your correction and it worked great, so great that it did not stop to print those greetings to my dear neighbours, i used the taskmanager then to stop the process :sweating:

So what would be the way to make the macro limit sending the message to one pressing of the hotkey ?

Share this post


Link to post
Share on other sites

FredX,

Entirely my fault - sorry. :blush:

I had tested using a key which did not feature in the sent text - but there are lots of "a" in that phrase and each time you send one it fires the HotKey again. So you need to cancel the HotKey on entry to the function and then reset it as you exit:

HotKeySet("a", "_A")

While 1
    Sleep(10) ;Keeps script running
WEnd

Func _A()
    HotKeySet("a") ; Prevent each "a" firing the function
    Send("Liebe Mitbewohner und Nachbarn,")
    HotKeySet("a", "_A") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A
That should keep your "neighbours" under control! :D

Seriously, you should use a modifier key as well as a character when you define the HotKey or you will find the same thing happening each time you type an "a" in the test. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Are you serious ?

It is a tool that lets you create macros that work off keystrokes. I used version 2 of it for many years and it saved me loads of trouble. Now it won't do the printer part however to make macros that work of keystrokes it does that quite well. Yes it is 8$ US but for what it does, it does it well.

Share this post


Link to post
Share on other sites

FredX,

Entirely my fault - sorry. :blush:

I had tested using a key which did not feature in the sent text - but there are lots of "a" in that phrase and each time you send one it fires the HotKey again. So you need to cancel the HotKey on entry to the function and then reset it as you exit:

HotKeySet("a", "_A")

While 1
    Sleep(10) ;Keeps script running
WEnd

Func _A()
    HotKeySet("a") ; Prevent each "a" firing the function
    Send("Liebe Mitbewohner und Nachbarn,")
    HotKeySet("a", "_A") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A
That should keep your "neighbours" under control! :D

Seriously, you should use a modifier key as well as a character when you define the HotKey or you will find the same thing happening each time you type an "a" in the test. ;)

M23

 

 

Not a prob at all, such happenings keep life fresh :thumbsup:

Glad the macro works so far. Now i tried to use more then 1 hotkeys and i just copied the first part again into the script and changed the variable to _B and the hotkey to 2 . 

HotKeySet("1", "_A")

While 1
    Sleep(10) ;Keeps script running
WEnd

Func _A()
    HotKeySet("1") ; Prevent each "a" firing the function
    Send("Liebe Mitbewohner und Nachbarn,")
    HotKeySet("1", "_A") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A



HotKeySet("2", "_B")

While 1
    Sleep(10) ;Keeps script running
WEnd

Func _B()
    HotKeySet("2") ; Prevent each "a" firing the function
    Send("mit freundlichen Grüßen")
    HotKeySet("2", "_B") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A

And while the first hotkey still works(i changed the "a" to "1"), the second does nothing, but at least i can start the macro and not getting a error message. But there seems to miss a part telling the macro "hey, there is another hotkey defined also, don't forget to work with it also".

How can i combine the 2 hotkeys so i have them both active and waiting ?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

FredX,

Your second HotKey instruction is never allowed to execute do to the 1ST while...wend loop.  Just move the HotKeySet like this...

HotKeySet("1", "_A")
HotKeySet("2", "_B")

While 1
    Sleep(10) ;Keeps script running
WEnd

Func _A()
    HotKeySet("1") ; Prevent each "a" firing the function
    Send("Liebe Mitbewohner und Nachbarn,")
    HotKeySet("1", "_A") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A




While 1
    Sleep(10) ;Keeps script running
WEnd

Func _B()
    HotKeySet("2") ; Prevent each "a" firing the function
    Send("mit freundlichen Grüßen")
    HotKeySet("2", "_B") ; Reset the HotKey ready for the next press
EndFunc   ;==>_A

;Liebe Mitbewohner und Nachbarn,2Liebe Mitbewohner und Nachbarn,mit freundlichen Grüßen

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Works great now. Just a last question, i tried to make a combination because using normal numbers can interfere with writing then. I tried

HotKeySet("LSHIFT+1")

and

HotKeySet("ALT+1")

but nothing happened, it just printed out "!", but examples show it like that, what did i do wrong ?

Share this post


Link to post
Share on other sites

FredX,

See M23's post (#4).  Also, see the Send command in the Help file for key definition...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Had overseen the hint of M23. I checked the helpfile and found out that instead of "ALT" the "!" is used.

So defining a hotkey with "!1" would mean ALT+1.

Interestingly it posted the word in the editor where i tried it out but then i could not do anything else, not pressing enter and nothing, stopped the script then but still. Then i shut down the autoit3-editor and  after a while of pressing all keys on different homepages and editors i am able to write again.

I don't know what i did wrong, it worked but i don't know why it screwed up my keys.

Another problem is, i only can do 5 posts more today.

 

EDIT: after finishing the macro and pressing alt+1 all went to normal, seems the macro set my keys into another mode anyhow.

Edited by FredX

Share this post


Link to post
Share on other sites

Anyway, my flat did not burn down, my pc still running, macro is working as planned now, thanks a lot to all who helped and have a good weekend ! :)

Share this post


Link to post
Share on other sites

I hope you removed the second (useless) while...wend loop..

Good Luck (and have a good weekend yourself),

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0