Sign in to follow this  
Followers 0
odklizec

strange problem with ClipGet

10 posts in this topic

Hi folks,

In my application for parsing copied strings, I found a strange behavior of ClipGet() function and I'm not sure if it's a feature or bug :D In case of strings copied with national characters, the returned strings (returned by ClipGet) contains bad characters.

Please, see the attached image and the below script. As you can see, the script is very basic. It just create a simple GUI with two inputs and single button. The first input is filled with clipboard after click on CGet button. To the second input I just pasted the copied string with Ctrl+V. Now the strange thing is, that some national characters appears wrong (in the first input using ClipGet) but they are OK in the second input (after Ctrl+V)? Also, the string pasted to notepad is OK too. And I can also write the national characters manually (with properly selected keyboard) and they appear OK in input.

I have to add that I'm using English OS with Czech and Slovak keyboard support installed. The regional settings for non-unicode programs is set to English. Of course, I tried to switch regional settings for non-unicode programs to Czech and then the below script works fine. The copied strings with national characters appear OK after ClipGet. But I still would like to know why the ClipGet works differently than usual Ctrl+V?

#include <GUIConstants.au3>

Dim $gui, $msg, $input_A, $input_B, $Button

    $gui = GUICreate("Parse web",400,200,-1,-1)
    $input_A = GUICtrlCreateInput ( "", 10, 10, 350, 18)
    $input_B = GUICtrlCreateInput ( "", 10, 60, 350, 18)
    $Button = GUICtrlCreateButton("CGet", 370, 10, 30, 20)  
    GUISetState(@SW_SHOW)

GUISetState()

While 1
    $msg = GUIGetMsg()
Select
    Case $msg = $Button
        GUICtrlSetData($input_A,ClipGet())
        ConsoleWrite(ClipGet())
    Case $msg = $GUI_EVENT_CLOSE 
        ExitLoop
    EndSelect
WEnd

Exit

Share this post


Link to post
Share on other sites



As far as I know (and I haven't really investigated this) AutoIt doesn't handle multibyte characters, unicode, or anything like that. It's ASCII only.

I could be wrong, but I'm pretty sure I've read that on the forum.

-mu

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for reply! That gives a sense :D

OK just another question related to this problem. Is there any way to set the Font SCRIPT (you know..western, central european, cyrillic, greek,...) to the selected GUI object? According to my tests in other application, if I set the the correct font script, the problem with incorrectly shown national characters go away with correct font Script.

Usually, the font Script can be set via small combo box in system Font dialog. Is there any way in AutoIt to do this via script? i did not find anything like that so I assume that's not currently possible?

Edited by odklizec

Share this post


Link to post
Share on other sites

Thanks for reply! That gives a sense :D

OK just another question related to this problem. Is there any way to set the Font SCRIPT (you know..western, central european, cyrillic, greek,...) to the selected GUI object? According to my tests in other application, if I set the the correct font script, the problem with incorrectly shown national characters go away with correct font Script.

Usually, the font Script can be set via small combo box in system Font dialog. Is there any way in AutoIt to do this via script? i did not find anything like that so I assume that's not currently possible?

Are you asking about a native GUI with AutoIt or another applications font? If AutoIt look at GUICtrlSetFont().

[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for reply! That gives a sense :D

OK just another question related to this problem. Is there any way to set the Font SCRIPT (you know..western, central european, cyrillic, greek,...) to the selected GUI object? According to my tests in other application, if I set the the correct font script, the problem with incorrectly shown national characters go away with correct font Script.

Usually, the font Script can be set via small combo box in system Font dialog. Is there any way in AutoIt to do this via script? i did not find anything like that so I assume that's not currently possible?

When I faced time ago with the close problem (this was Send function), I found that changing active keyboard layout for needed application to national fixing this trouble. So small UDf was written, you can try if it will work for you with Clip* functions.

#include-once
;
; Description:      Get keyboard layout from given window
; Parameter(s):     Window handle
; Requirement(s):   Autoit 3.103
; Return Value(s):  String with language ID
; Author(s):        YDY (Lazycat)
; Version:          1.0
; Date:             7.06.2005

Func _GetKeyboardLayout($hWnd)
    Local $ret = DllCall("user32.dll", "long", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", 0)
          $ret = DllCall("user32.dll", "long", "GetKeyboardLayout", "long", $ret[0])
          Return "0000" & Hex($ret[0], 4)
EndFunc

;
; Description:      Set keyboard layout in the given window
; Parameter(s):     Language ID string, window handle
; Requirement(s):   Autoit 3.103
; Return Value(s):  None
; Author(s):        YDY (Lazycat)
; Version:          1.0
; Date:             7.06.2005

Func _SetKeyboardLayout($sLayoutID, $hWnd)
    Local $WM_INPUTLANGCHANGEREQUEST = 0x50
    Local $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", $sLayoutID, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, _
                                                "int", $WM_INPUTLANGCHANGEREQUEST, _
                                                "int", 1, _
                                                "int", $ret[0])
EndFunc
Edited by Lazycat

Share this post


Link to post
Share on other sites

Are you asking about a native GUI with AutoIt or another applications font? If AutoIt look at GUICtrlSetFont().

Thanks! Of course, I know this function. But I did not find anything like "Script" option here?

Share this post


Link to post
Share on other sites

When I faced time ago with the close problem (this was Send function), I found that changing active keyboard layout for needed application to national fixing this trouble. So small UDf was written, you can try if it will work for you with Clip* functions.

NIce! I will give it a try :D Thank you!

Share this post


Link to post
Share on other sites

to Lazycat..

OK, I tried your UDF. The _GetKeyboardLayout works fine. It returns the code of actual (manually set by Alt+Shift) keyboard layout -> 409 for english, 405 for Czech, etc.. Unfortunately, I tried both hex or dec representation of Czech keyboard layout (405=1029) but none of them switched the keyboard? from actual 409 (English) keyboard. Any idea why? Here is the code..

#include <GUIConstants.au3>
#include <KeyboardLayout.au3>

Dim $gui, $msg, $input_A, $input_B, $Button,$klayout

    $gui = GUICreate("Parse web",400,200,-1,-1)
    $input_A = GUICtrlCreateInput ( "", 10, 10, 350, 18)
    $input_B = GUICtrlCreateInput ( "", 10, 60, 350, 18)
    $Button = GUICtrlCreateButton("CGet", 370, 10, 30, 20)  
    $Button_2 = GUICtrlCreateButton("CGet", 370, 60, 30, 20)    
    $Button_3 = GUICtrlCreateButton("get cur. lang. code", 10, 90, 100, 20)
; set keyboard layout
    $klayout=_SetKeyboardLayout(1029, $gui)
; it always returns 0
    ConsoleWrite("Set keyb.: " &$klayout&@LF)
    GUISetState(@SW_SHOW)

GUISetState()

While 1
    $msg = GUIGetMsg()
Select
    Case $msg = $Button
        GUICtrlSetData($input_A,ClipGet())
        ConsoleWrite(ClipGet())
    Case $msg = $Button_2
        $line = FileReadLine("c:\test\test2.txt",2)
        GUICtrlSetData($input_B,$line)
    Case $msg = $Button_3
        $klayout=_GetKeyboardLayout($gui)
        ConsoleWrite("Get keyb.: " & $klayout&@LF)
    Case $msg = $GUI_EVENT_CLOSE 
        ExitLoop
    EndSelect
WEnd

Exit

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Function accept 8-chars string as parameter, maybe this cause? This probably should look like "00000405" in your case. Here is quick test for functions:

#include <KeyboardLayout.au3>
Opt("WinTitleMatchMode", 4)
Run("notepad.exe")
Sleep(500)
$hWnd = WinGetHandle("classname=Notepad")
MsgBox (0, "Old Layout", _GetKeyboardLayout($hWnd))
_SetKeyboardLayout("00000405", $hWnd)
MsgBox (0, "New Layout", _GetKeyboardLayout($hWnd))

BTW, _SetKeyboardLayout return nothing, this was copypaste mistake in description...

Edited by Lazycat

Share this post


Link to post
Share on other sites

Function accept 8-chars string as parameter, maybe this cause? This probably should look like "00000405" in your case. Here is quick test for functions:

#include <KeyboardLayout.au3>
Opt("WinTitleMatchMode", 4)
Run("notepad.exe")
Sleep(500)
$hWnd = WinGetHandle("classname=Notepad")
MsgBox (0, "Old Layout", _GetKeyboardLayout($hWnd))
_SetKeyboardLayout("00000405", $hWnd)
MsgBox (0, "New Layout", _GetKeyboardLayout($hWnd))

BTW, _SetKeyboardLayout return nothing, this was copypaste mistake in description...

OK, I got it to work. Thanks! I had to change the WinGetHandle with GUICtrlGetHandle pointing to the Input box. Although it nicely change the keyboard layout, it does not fix my problem. Nevermind. The trick with regional settings works fine, so I can live with that. But it would be nice to have an option to set the font script in GUI objects and of course, get the clipboard content unchanged :D I still think it's something wrong with ClipGet, because Ctrl+V works fine here.

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