 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TAB4217
Joined: 13 Sep 2007 Posts: 4 Location: Haiti
|
Posted: Wed Oct 24, 2007 4:18 pm Post subject: SendU: hex, or dec? |
|
|
But it seems that SendInputU requires a hex string while SendU works with a decimal string. For example, the following script sends twice the same Delta when F5 is hit:
F5:: ;Delta
SendU("0916") ; decimal string
SendInputU("0394") ; equivalent hex string
return
Confusing! Should not the hex string (given by Character map, for example) be standard?  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Wed Oct 24, 2007 6:32 pm Post subject: Re: SendU: hex, or dec? |
|
|
| SendInputU requires a hex string, of multiple character codes to be sent. SendU sends just one Unicode character. Its parameter is a number, the code. AHK treats numerical strings as numbers, but you can safely remove the quotes. SendU("0916"), SendU(916), SendU("0x0394") or SendU(0x394) all should do the same thing. |
|
| Back to top |
|
 |
fmate14
Joined: 28 Oct 2007 Posts: 59 Location: Hungary, Érd
|
Posted: Tue Jan 22, 2008 9:31 am Post subject: |
|
|
| Lester Wong wrote: | | So why doesn't it work in Skype? |
Try the Extended SendU function |
|
| Back to top |
|
 |
rousni
Joined: 23 Mar 2006 Posts: 46
|
Posted: Sun Aug 24, 2008 7:50 am Post subject: What is an example of an application where this method fails |
|
|
| Quote: | | What is an example of an application where this method fails? |
This method fails with Autohotkey's edit controls (Cyrillic letters; Vista) |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1143 Location: The Interwebs
|
Posted: Sun Aug 24, 2008 8:59 am Post subject: |
|
|
| The method doesn't fail, it is AutoHotkey that fails, unfortunately. AutoHotkey does not have Unicode support ): |
|
| Back to top |
|
 |
rousni
Joined: 23 Mar 2006 Posts: 46
|
Posted: Sun Aug 24, 2008 10:33 am Post subject: |
|
|
Yes I see, it is AutoHotkey that fails.
On the other hand, sending ^v works well, luckily! |
|
| Back to top |
|
 |
jak
Joined: 28 Feb 2006 Posts: 116
|
Posted: Thu Sep 04, 2008 1:57 am Post subject: |
|
|
Hi guys, In looking for a way to type French accents in any program, I came upon this great dll version (instead of the ^v version) and I thought maybe it would be faster or more efficient (is that true? I'm currently using a ^v version and I find that sometimes when I type fast, my keyboard now skips vowels ("a" or "e" etc) where it didnt used to do so before). So I tried utilizing the dll version above. And for the most part, it works - but can anyone tell me why the below doesnt work in MS Word 2007? (It does seem to work in other programs, like Notepad). In Word however, pressing the hotkeys below produces absolutely nothing.
| Code: | ;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
DllCall("LoadLibrary", Str,"ntdll.dll")
VarSetCapacity( SendUbuf, 56, 0 ) ; INIT SendU data strucure
DllCall("RtlFillMemory", UInt,&SendUbuf, UInt,1, UInt,1)
DllCall("RtlFillMemory", UInt,&SendUbuf+28, UInt,1, UInt,1)
^a::SendU(0x0101)
^b::SendU(0x00E1)
^c::SendU(0x01CE)
; ...
SendU(UC) { ; Send Unicode Char, Pressed modifier keys stay active!
Global
DllCall("ntdll.dll\RtlFillMemoryUlong",UInt,&SendUbuf+6, UInt,4,UInt,0x40000|UC) ;KEYEVENTF_UNICODE
DllCall("ntdll.dll\RtlFillMemoryUlong",UInt,&SendUbuf+34,UInt,4,UInt,0x60000|UC) ;KEYEVENTF_KEYUP|^
Return DllCall("SendInput", UInt,2, UInt,&SendUbuf, Int,28)
}
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu Sep 04, 2008 5:23 am Post subject: |
|
|
The comment says: Pressed modifier keys stay active! As explained here: The SendInputU function does not change the state of the modifier keys. If you use it in a hotkey subroutine, like Ctrl-F1, the sent keys will all behave as Ctrl-key combinations, while the user holds the Ctrl key down. You have to do something to fake a release of the Ctrl key, or wait until it is released by the user (KeyWait Ctrl).
Btw, the RtlFillMemoryUlong dll calls can be replaced now by NumPut's. |
|
| Back to top |
|
 |
jak
Joined: 28 Feb 2006 Posts: 116
|
Posted: Thu Sep 04, 2008 4:44 pm Post subject: |
|
|
| Laszlo wrote: | | If you use it in a hotkey subroutine, like Ctrl-F1, the sent keys will all behave as Ctrl-key combinations, while the user holds the Ctrl key down. You have to do something to fake a release of the Ctrl key, or wait until it is released by the user (KeyWait Ctrl). |
hi lazlso - ok, keywait ctrl works, thanks for that
| Quote: |
Btw, the RtlFillMemoryUlong dll calls can be replaced now by NumPut's. |
pls bear with me, i'm just a hacker and i dont really understand whats happening at the level of the dll calls... so what would I change the rtlfillmemory lines to? and what would be the advantage of using numputs instead? would it be faster or more efficient? thanks! |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu Sep 04, 2008 6:07 pm Post subject: |
|
|
| jak wrote: | | so what would I change the rtlfillmemory lines to? and what would be the advantage of using numputs instead? | Shorter, cleaner code: | Code: | ;;;;; ----- Send Unicode Character
VarSetCapacity(SendUbuf, 56, 0) ; INIT SendU data strucure
NumPut(1, SendUbuf, 0, "Char")
NumPut(1, SendUbuf,28, "Char")
:*?:a':: ; hotstring example
SendU(0x00E1)
Return
#!p:: ; hotkey example
KeyWait LWin
KeyWait RWin ; wait until all modifiers are released
KeyWait Alt
SendU(0x203F)
Return
SendU(UC) { ; Send Unicode Char, Pressed modifier keys stay active!
Global SendUbuf
NumPut(0x40000|UC, SendUbuf, 6)
NumPut(0x60000|UC, SendUbuf,34)
Return DllCall("SendInput", UInt,2, UInt,&SendUbuf, Int,28)
} |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu Sep 04, 2008 6:35 pm Post subject: |
|
|
If you are after speed, you could try this version: | Code: | ;;;;; ----- Send Unicode Character
VarSetCapacity(SendUbuf, 56, 0) ; INIT SendU data strucure
NumPut(1, SendUbuf, 0, "Char")
NumPut(1, SendUbuf,28, "Char")
NumPut(0x40000, SendUbuf, 6)
NumPut(0x60000, SendUbuf,34)
:*?:a':: ; hotstring
SendU(0x00E1)
Return
#!p:: ; hotkey
KeyWait LWin
KeyWait RWin ; wait until all modifiers are released
KeyWait Alt
SendU(0x2714)
Return
SendU(UC) { ; Send Unicode Char, Pressed modifier keys stay active!
Global SendUbuf
NumPut(UC, SendUbuf, 6, "Short")
NumPut(UC, SendUbuf,34, "Short")
Return DllCall("SendInput", UInt,2, UInt,&SendUbuf, Int,28)
} | It trades bitwise OR operations to parsing an extra parameter in two NumPuts. It could be slightly faster, dependent on your system. Another speedup possibility is Lexikos’ trick: | Code: | ;;;;; ----- Send Unicode Character
SendInput:=DllCall("GetProcAddress",UInt,DllCall("GetModuleHandle",Str,"user32"),Str,"SendInput")
VarSetCapacity(SendUbuf, 56, 0) ; INIT SendU data strucure
NumPut(1, SendUbuf, 0, "Char")
NumPut(1, SendUbuf,28, "Char")
NumPut(0x40000, SendUbuf, 6)
NumPut(0x60000, SendUbuf,34)
:*?:a':: ; hotstring
SendU(0x00E1)
Return
#!p:: ; hotkey
KeyWait LWin
KeyWait RWin ; wait until all modifiers are released
KeyWait Alt
SendU(0x2714)
Return
SendU(UC) { ; Send Unicode Char, Pressed modifier keys stay active!
Global ; SendUbuf, SendInput
NumPut(UC, SendUbuf, 6, "Short")
NumPut(UC, SendUbuf,34, "Short")
Return DllCall(SendInput, UInt,2, UInt,&SendUbuf, Int,28)
} |
|
|
| Back to top |
|
 |
jak
Joined: 28 Feb 2006 Posts: 116
|
Posted: Thu Sep 04, 2008 7:09 pm Post subject: |
|
|
| Quote: | | Shorter, cleaner code: |
Thanks much! i'll try these - one question though -- when I tried your first numput version above in NOTEPAD, with french accents, I was getting a font that was smaller in size than the normal way.
For example, see the attached pic. The "very small" letter e, with the accent grave, is using the numput method. The "normal size" letter e with accent grave, is from using the "transform and control-V" method.
Any idea why the two sizes would be different in NOTEPAD? (They work normally in MS Word, by the way)
[/img] |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu Sep 04, 2008 7:31 pm Post subject: |
|
|
| You have more possibilities for è: the Unicode 0x00E8 character (Alt+NumPad 0232) or the US OEM 0x8A (Alt+Numpad 138) character. Your localized fonts (codepage) could use another ANSI code, too. What is the code you send? Try another possibility to see if it gives you the right size. Notepad can only show one font, but this font could have more than one versions of è. |
|
| Back to top |
|
 |
jak
Joined: 28 Feb 2006 Posts: 116
|
Posted: Thu Sep 04, 2008 8:40 pm Post subject: |
|
|
| Laszlo wrote: | | What is the code you send? |
I think one difference is that the "transform and control-V" method is actually using the alt+codes, whereas Numpad is using unicode?
For example, my "transform and control V" version looks like this: (code snippet only:)
| Code: |
^e::
Transform, Clipboard, Unicode, è ;sendinput,è
sendinput ^{v}
return
|
Whereas the numput looks like this:
| Code: |
^e::
keywait, ctrl
SendU(0x0450) ;send è
return
|
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Thu Sep 04, 2008 9:02 pm Post subject: |
|
|
| Why do you use the Cyrillic è character (0x0450)? It is matched with the other Cyrillic letters (smaller). The Latin-1 Supplement version (0x00E8) should be better for Latin languages with SendU. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|