Jump to content

Recommended Posts

Posted

Hi.

I just came across these two functions:

_WinAPI_GetKeyboardLayout()
_WinAPI_GetKeyboardLayoutList()

 

That's something, that would be quite helpfull sometimes at a server, where I want a different keyboard layout, but I already fail to *GET* the current layout or the list of layouts.

 

#include <WinAPISys.au3>



$LayoutList=_WinAPI_GetKeyboardLayoutList
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $LayoutList = ' & $LayoutList & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$VarType=VarGetType($LayoutList)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $VarType = ' & $VarType & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$layout=_WinAPI_GetKeyboardLayout
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $layout = ' & $layout & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$VarType=VarGetType($Layout)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $VarType = ' & $VarType & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; _WinAPI_ActivateKeyboardLayout
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\forum.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(6) : $LayoutList = 
>Error code: 0
@@ Debug(8) : $VarType = UserFunction
>Error code: 0
@@ Debug(10) : $layout = 
>Error code: 0
@@ Debug(12) : $VarType = UserFunction
>Error code: 0
+>12:57:26 AutoIt3.exe ended.rc:0
+>12:57:26 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.7655

 

What is the variable type "UserFunction"?

Looking up the functions in WinApiSYS.AU3 I'd expect either to receive an @error value or an array to be returned.

$hWnd propably shall be a window handle, isn't it?

WinAPISys.au3
-------------------
[snip]

; #FUNCTION# ====================================================================================================================
; Author.........: Yashied
; Modified.......: Jpm
; ===============================================================================================================================
Func _WinAPI_GetKeyboardLayout($hWnd)
    Local $aRet = DllCall('user32.dll', 'dword', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
    If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0)

    $aRet = DllCall('user32.dll', 'handle', 'GetKeyboardLayout', 'dword', $aRet[0])
    If @error Then Return SetError(@error, @extended, 0)
    ; If Not $aRet[0] Then Return SetError(1000, 0, 0)

    Return $aRet[0]
EndFunc   ;==>_WinAPI_GetKeyboardLayout

; #FUNCTION# ====================================================================================================================
; Author.........: Yashied
; Modified.......: jpm
; ===============================================================================================================================
Func _WinAPI_GetKeyboardLayoutList()
    Local $aRet = DllCall('user32.dll', 'uint', 'GetKeyboardLayoutList', 'int', 0, 'ptr', 0)
    If @error Or Not $aRet[0] Then Return SetError(@error + 20, @extended, 0)

    Local $tData = DllStructCreate('handle[' & $aRet[0] & ']')
    $aRet = DllCall('user32.dll', 'uint', 'GetKeyboardLayoutList', 'int', $aRet[0], 'struct*', $tData)
    If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0)

    Local $aList[$aRet[0] + 1] = [$aRet[0]]
    For $i = 1 To $aList[0]
        $aList[$i] = DllStructGetData($tData, 1, $i)
    Next
    Return $aList
EndFunc   ;==>_WinAPI_GetKeyboardLayoutList
[/snip]

What do I miss?

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted (edited)
1 hour ago, rudi said:

What do I miss?

 

1 hour ago, rudi said:

 

There is a difference between

$LayoutList=_WinAPI_GetKeyboardLayoutList

And

$LayoutList=_WinAPI_GetKeyboardLayoutList()

One assigns a user function to a variable and the other assigns the return value of the user function to a variable.

 

Edited by TheXman
  • 2 weeks later...
Posted (edited)
On 7/22/2020 at 1:54 PM, TheXman said:

 

 

There is a difference between

$LayoutList=_WinAPI_GetKeyboardLayoutList

And

$LayoutList=_WinAPI_GetKeyboardLayoutList()

One assigns a user function to a variable and the other assigns the return value of the user function to a variable.

 

Doh 😣

 

Thx!

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
×
×
  • Create New...