Sign in to follow this  
Followers 0
lbrtdy

Different Send Modes?

3 posts in this topic

I type in a different keyboard layout -Dvorak- and when I try to use autoit to send something, it ends up sending the wrong key(s). Ie Send("s") it would go to the physical e on my keyboard and tries to send that, but it turn because of my layout, sends an "o". Is there a way to change it so that autoit sends it in a different way that overcomes my layout problems?

Share this post


Link to post
Share on other sites



I type in a different keyboard layout -Dvorak- and when I try to use autoit to send something, it ends up sending the wrong key(s). Ie Send("s") it would go to the physical e on my keyboard and tries to send that, but it turn because of my layout, sends an "o". Is there a way to change it so that autoit sends it in a different way that overcomes my layout problems?

Maybe follows.

#Include <WinAPI.au3>

HotKeySet('^s', '_Send')
HotKeySet('^q', '_Quit')

While 1
    Sleep(100)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func _Send()
    $hWnd = WinGetHandle('[ACTIVE]')
    If @error Then
        Return
    EndIf
    $sLayout = _WinAPI_GetKeyboardLayout($hWnd)
    _WinAPI_SetKeyboardLayout('00000409', $hWnd)
    Send('Test' & @CRLF)
    _WinAPI_SetKeyboardLayout($sLayout, $hWnd)
EndFunc   ;==>_Send

Func _WinAPI_GetKeyboardLayout($hWnd)

    Local $Ret = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)

    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    $Ret = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $Ret[0])
    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    Return '0000' & Hex($Ret[0], 4)
EndFunc   ;==>_WinAPI_GetKeyboardLayout

Func _WinAPI_SetKeyboardLayout($sLayout, $hWnd)

    If Not _WinAPI_IsWindow($hWnd) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $Ret = DllCall('user32.dll', 'long', 'LoadKeyboardLayout', 'str', StringFormat('%08s', StringStripWS($sLayout, 8)), 'int', 0)

    If (@error) Or ($Ret[0] = 0) Then
        Return SetError(1, 0, 0)
    EndIf
    DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'int', 0x50, 'int', 1, 'int', $Ret[0])
    Return SetError(0, 0, 1)
EndFunc   ;==>_WinAPI_SetKeyboardLayout

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

No that didn't work, the thing is that my Windows is set as default Qwerty layout, I didn't touch it. But I run a program written in autohotkey that remaps the whole keyboard. So is there what is equivalent to autohotkey's SendMode, input or Sendmode, Raw in autoit? So it would ignore the current configuration of the keyboard and just sends the text specified? I'm not referring to sending raw as it send ! would equal alt, but as it Send o it won't go to o on my keyboard and sends that, but due to my layout it sends an "r".

Edited by lbrtdy

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