Sign in to follow this  
Followers 0
veldrinn

Send function

7 posts in this topic

One of my first programs: creates shortcuts to characters used in spanish.

For some reason the send() function didn't work with chr() until i sent a character and backspaced it. I'm not sure what went wrong originally but i replaced Send(Chr($s)) with Send("|" & "{backspace}" & Chr($s)) and that seems to work.

Could someone tell me why?

#NoTrayIcon
If WinExists("_specialchars") Then Exit
AutoItWinSetTitle("_specialchars")
HotKeySet("^!q","fexit")
HotKeySet("^!a", "fkey")
HotKeySet("^!+a", "fkey")
HotKeySet("^!e", "fkey")
HotKeySet("^!+e", "fkey")
HotKeySet("^!i", "fkey")
HotKeySet("^!+i", "fkey")
HotKeySet("^!o", "fkey")
HotKeySet("^!+o", "fkey")
HotKeySet("^!u", "fkey")
HotKeySet("^!+u", "fkey")
HotKeySet("^!n", "fkey")
HotKeySet("^!+n", "fkey")
HotKeySet("^!1", "fkey2")
HotKeySet("^!/", "fkey2")
Func fkey()
    If @HotKeyPressed = "^!a" Then $s = 225
    If @HotKeyPressed = "^!+a" Then $s = 0193
    If @HotKeyPressed = "^!e" Then $s = 233
    If @HotKeyPressed = "^!+e" Then $s = 201
    If @HotKeyPressed = "^!i" Then $s = 237
    If @HotKeyPressed = "^!+i" Then $s = 205
    If @HotKeyPressed = "^!o" Then $s = 243
    If @HotKeyPressed = "^!+o" Then $s = 211
    If @HotKeyPressed = "^!u" Then $s = 250
    If @HotKeyPressed = "^!+u" Then $s = 218
    If @HotKeyPressed = "^!n" Then $s = 241
    If @HotKeyPressed = "^!+n" Then $s = 209
    Send("|" & "{backspace}" & Chr($s))  
EndFunc
Func fkey2()
    If @HotKeyPressed = "^!1" Then $s = 173
    If @HotKeyPressed = "^!/" Then $s = 168
    Send("|" & "{backspace}" & "{asc " & $s & "}")
EndFunc
Func fexit()
    Exit
EndFunc
While 1
    Sleep(1000)
WEnd

Thanks

Share this post


Link to post
Share on other sites



...i replaced Send(Chr($s)) with Send("|" & "{backspace}" & Chr($s)) and that seems to work...

Welcome to the forum.

$s = 209
Send(Chr($s))
works fine for me using AutoIt v3.2.2.0 and notepad.

What application are you sending it to?


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Welcome to the forum.

Thanks! I just started AutoIt a few weeks ago.

Anyway, I tried Notepad and Word. Neither worked. I dunno, its probably just my computer, its temperamental. I need to upgrade from Me ...

Share this post


Link to post
Share on other sites

Just for fun, run just those two lines of code from within SciTE and report your findings.

Also, if you lower the Opt setting for SendKeyDelay, you might not notice the "backspace work around" that you seem to have found.

I do not see any code in the script that you posted that is OS sensitive... it should work in ME, but since you have a work around, then you might just use that code.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This works for me:

$s = 209

Send(Chr($s))

but when I use it in the program, it doesn't...

It seems that its not even starting the send command when it is after the if/then's. What is even odder is that if I add a message box before the send, it also works.

Just for fun, run just those two lines of code from within SciTE and report your findings.

I do not see any code in the script that you posted that is OS sensitive... it should work in ME, but since you have a work around, then you might just use that code.

SciTE doesn't say anything unusual, just the AutoIt check ended, AutoIt wrapper, etc. I think I'll just use the work around and set the Opt() setting like you said.

Thanks

Edited by veldrinn

Share this post


Link to post
Share on other sites

...SciTE doesn't say anything unusual...

Sorry, I just meant for you to run those two lines of code from within the SciTE editor and let them type directly into SciTE window - no winwaits or winactivates to get to Notepad or any other another app. That would make your test just about like mine.... but it sounds like those two lines work, but not in your script.

That is weird - maybe others have some input on this - even if you have your workaround, it is nice to know why somethings happen.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hmmm, I disabled/enabled the hotkeys, it didn't send the char... I trapped the active hwnd, and reactivated it in case it lost focus, that sent once... I put Sleep(xxx) all the way to 250 and a 1000 and those seemed to work.

Something really odd about that IMHO.

CODE
;#NoTrayIcon
;Opt('SendKeyDelay', 50)
_EnableHotKeys()
If WinExists("_specialchars") Then Exit
AutoItWinSetTitle("_specialchars")

While 1
    Sleep(100000)
WEnd

Func fkey()
    Local $sHotKeyPressed = @HotKeyPressed, $s = ''
    ;_DisableHotKeys()
    ;Local $hWnd = WinGetHandle('')
    If $sHotKeyPressed = "^!a" Then $s = 225
    If $sHotKeyPressed = "^!+a" Then $s = 0193
    If $sHotKeyPressed = "^!e" Then $s = 233
    If $sHotKeyPressed = "^!+e" Then $s = 201
    If $sHotKeyPressed = "^!i" Then $s = 237
    If $sHotKeyPressed = "^!+i" Then $s = 205
    If $sHotKeyPressed = "^!o" Then $s = 243
    If $sHotKeyPressed = "^!+o" Then $s = 211
    If $sHotKeyPressed = "^!u" Then $s = 250
    If $sHotKeyPressed = "^!+u" Then $s = 218
    If $sHotKeyPressed = "^!n" Then $s = 241
    If $sHotKeyPressed = "^!+n" Then $s = 209
    Local $sChar = Chr($s)
    ;If Not WinActive($hWnd) Then WinActivate($hWnd)
    Sleep(250)
    Send($sChar)  
    _EnableHotKeys()
EndFunc
Func _EnableHotKeys()
    HotKeySet("^!q","fexit")
    HotKeySet("^!a", "fkey")
    HotKeySet("^!+a", "fkey")
    HotKeySet("^!e", "fkey")
    HotKeySet("^!+e", "fkey")
    HotKeySet("^!i", "fkey")
    HotKeySet("^!+i", "fkey")
    HotKeySet("^!o", "fkey")
    HotKeySet("^!+o", "fkey")
    HotKeySet("^!u", "fkey")
    HotKeySet("^!+u", "fkey")
    HotKeySet("^!n", "fkey")
    HotKeySet("^!+n", "fkey")
    HotKeySet("^!1", "fkey2")
    HotKeySet("^!/", "fkey2")
EndFunc
Func _DisableHotKeys()
    HotKeySet("^!q")
    HotKeySet("^!a")
    HotKeySet("^!+a")
    HotKeySet("^!e")
    HotKeySet("^!+e")
    HotKeySet("^!i")
    HotKeySet("^!+i")
    HotKeySet("^!o")
    HotKeySet("^!+o")
    HotKeySet("^!u")
    HotKeySet("^!+u")
    HotKeySet("^!n")
    HotKeySet("^!+n")
    HotKeySet("^!1")
    HotKeySet("^!/")
EndFunc
Func fkey2()
    If @HotKeyPressed = "^!1" Then $s = 173
    If @HotKeyPressed = "^!/" Then $s = 168
    Send("|" & "{backspace}" & "{asc " & $s & "}")
EndFunc
Func fexit()
    Exit
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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