Jump to content
Sign in to follow this  
davidp

Help with Send Key script

Recommended Posts

davidp

I have a script (see below) that sends a few keys but it erroring out on me. If anyone can help, I'd appreciate it.

When I run it I get error:

Line 15

alt+q = 4+3+2

alt^ERROR

Error: Missing separator character after keyword.

Script below:

HotKeySet("!q", "AltQ")

HotKeySet("!w", "AltW")

HotKeySet("!e", "AltE")

HotKeySet("!r", "AltR")

HotKeySet("!t", "AltT")

HotKeySet("!y", "AltY")

HotKeySet("!u", "AltU")

HotKeySet("{ESC}", "Escape")

While 1

Sleep(10)

WEnd

alt+q = 4+3+2

alt+w = 5+2+3

alt+e = 6+2+1

alt+r = 7+3+1

alt+t = 8+1+3

alt+y = 9+1+2+3

alt+u = 0+q+1+3

Func AltQ()

P("432")

EndFunc

Func AltW()

P("523")

EndFunc

Func AltE()

P("621")

EndFunc

Func AltR()

P("731")

EndFunc

Func AltT()

P("813")

EndFunc

Func AltY()

P("9123")

EndFunc

Func AltU()

P("0q13")

EndFunc

Func P($k)

Send(StringMid($k, 0, 1))

Sleep(1000)

Send(StringMid($k, 1, 1))

Sleep(500)

Send(StringMid($k, 2, 1))

Sleep(500)

If StringLen($k) = 4 Then Send(StringMid($k, 3, 1))

EndFunc

Func Escape()

Exit

EndFunc

Share this post


Link to post
Share on other sites
martin

I have a script (see below) that sends a few keys but it erroring out on me. If anyone can help, I'd appreciate it.

When I run it I get error:

Line 15

alt+q = 4+3+2

alt^ERROR

Error: Missing separator character after keyword.

Script below:

HotKeySet("!q", "AltQ")

HotKeySet("!w", "AltW")

HotKeySet("!e", "AltE")

HotKeySet("!r", "AltR")

HotKeySet("!t", "AltT")

HotKeySet("!y", "AltY")

HotKeySet("!u", "AltU")

HotKeySet("{ESC}", "Escape")

While 1

Sleep(10)

WEnd

alt+q = 4+3+2

alt+w = 5+2+3

alt+e = 6+2+1

alt+r = 7+3+1

alt+t = 8+1+3

alt+y = 9+1+2+3

alt+u = 0+q+1+3

Func AltQ()

P("432")

EndFunc

Func AltW()

P("523")

EndFunc

Func AltE()

P("621")

EndFunc

Func AltR()

P("731")

EndFunc

Func AltT()

P("813")

EndFunc

Func AltY()

P("9123")

EndFunc

Func AltU()

P("0q13")

EndFunc

Func P($k)

Send(StringMid($k, 0, 1))

Sleep(1000)

Send(StringMid($k, 1, 1))

Sleep(500)

Send(StringMid($k, 2, 1))

Sleep(500)

If StringLen($k) = 4 Then Send(StringMid($k, 3, 1))

EndFunc

Func Escape()

Exit

EndFunc

The lines

alt+q = 4+3+2
alt+w = 5+2+3
alt+e = 6+2+1
alt+r = 7+3+1
alt+t = 8+1+3
alt+y = 9+1+2+3
alt+u = 0+q+1+3

need to be removed or commented out. They don't make sense as far as AutoIt is concerned, and even if they did the script will not get past the while loop which precedes them.

If you were trying to make variables for the strings then

$altq = "432"
;or
$altq = "4" & "3" & "2"

The first character of a string in string functions is at position 1, so

StringMid($k, 0, 1)

will return an empty string because the start position is invalid.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
davidp

Actually I was trying to use alt + a key letter in the hotkey, so I was not trying to create a variable.

Also for the start string, I'm not sure about this: StringMid($k, 0, 1)...either.

Share this post


Link to post
Share on other sites
davidp

Well, I got one step closer, but something is still missing.

By taking this out:

alt+q = 4+3+2

alt+w = 5+2+3

alt+e = 6+2+1

alt+r = 7+3+1

alt+t = 8+1+3

alt+y = 9+1+2+3

alt+u = 0+q+1+3

I was able to run the script and tested it in notepad.

In notepad I hit alt+q or other hot key letters, the results are random...

For alt+q...only number 3 is shown in notepad

alt+w...only number 2 is shown in notepad

alt+t...only number 8 is showin in notepad

alt+y...only numbers 912 is shown in notepad

alt+u...only numbers/letter 0q1 is shown in notepad

here is what I have for the modified script:

HotKeySet("!q", "AltQ")

HotKeySet("!w", "AltW")

HotKeySet("!e", "AltE")

HotKeySet("!r", "AltR")

HotKeySet("!t", "AltT")

HotKeySet("!y", "AltY")

HotKeySet("!u", "AltU")

HotKeySet("{ESC}", "Escape")

While 1

Sleep(10)

WEnd

Func AltQ()

P("432")

EndFunc

Func AltW()

P("523")

EndFunc

Func AltE()

P("621")

EndFunc

Func AltR()

P("731")

EndFunc

Func AltT()

P("813")

EndFunc

Func AltY()

P("9123")

EndFunc

Func AltU()

P("0q13")

EndFunc

Func P($k)

Send(StringMid($k, 0, 1))

Sleep(1000)

Send(StringMid($k, 1, 1))

Sleep(500)

Send(StringMid($k, 2, 1))

Sleep(500)

If StringLen($k) = 4 Then Send(StringMid($k, 3, 1))

EndFunc

Func Escape()

Exit

EndFunc

Share this post


Link to post
Share on other sites
k3v

Your stringmid functions are only sending 1 character... strings start at 1, (not 0) and your count parameter is only allowing for 1 character...

so for example:

Send(StringMid($k, 0, 1))

should look like this...

Send(StringMid($k, 1, 3))

try that

Share this post


Link to post
Share on other sites
davidp

That didn't work. The results pattern changed. I know I'm pretty close but can't get the pattern to come out with the 3 numbers posted in notepad. If anyone know of another way of making it output the 3 numbers or 4 numbers in the proper pattern from left to right, that would work as well. Thanks in advance.

Share this post


Link to post
Share on other sites
k3v

I must apologize, since I misunderstood your P() function and probably confused the matter. Allow me to make up for the misunderstanding and attempt one more suggestion.

I think I see more clearly now, and a similar problem applies here:

Func P($k)

Send(StringMid($k, 0, 1))

------------------------^ change to 1... eg: StringMid($k, 1, 1)

Sleep(1000)

Send(StringMid($k, 1, 1))

------------------------^ change to 2

Sleep(500)

Send(StringMid($k, 2, 1))

------------------------^ change to 3

Sleep(500)

If StringLen($k) = 4 Then Send(StringMid($k, 3, 1))

--------------------------------------------------------^ change to 4

EndFunc

If this doesn't do it I promise to leave you alone, with my apologies.

Edited by k3v

Share this post


Link to post
Share on other sites
davidp

Thanks KV3, no need to apologize. You were very nice to reply to me.

Using your tip, I was able to get the output results to go from left to right, but now it's missing the last digit. So I'm almost there, hehe.

Share this post


Link to post
Share on other sites
k3v

When I tested your script, I missed the first character. When I added a short sleep before the first send, I get all of them.

Share this post


Link to post
Share on other sites
davidp

Mind if I ask you what you changed each of the short sleep to or just the first one to? I just tested changing the first sleep to 200 after the first send and I didn't get all the numbers. If you can paste your version of the script, I'll give it a try again. Thanks for the help.

Share this post


Link to post
Share on other sites
k3v

just added the first one...

Func P($k)
sleep(1000)
Send(StringMid($k, 1, 1))
Sleep(1000)
Send(StringMid($k, 2, 1))
Sleep(500)
Send(StringMid($k, 3, 1))
Sleep(500)
If StringLen($k) = 4 Then Send(StringMid($k, 4, 1))
EndFunc

Curious... I added a line to run Notepad to send these strings for testing... are you using something different?

Edited by k3v

Share this post


Link to post
Share on other sites
davidp

K3v,

I finally got it to work.

I got it it to work after looking at your part of the script. What I did wrong was that I miss read your message earlier. You wrote..."When I added a short sleep before the first send, I get all of them." I interpreted as you added a short sleep after the first send. My mistake.

All I do is use notepad to test it. I run the script, launch notepad, and then I just hit alt+q and so on.

Thanks for all your help.

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  

×