Sujet : Re: Remove new line char
De : apnmbx-public (at) *nospam* yahoo.com (Ashok)
Groupes : comp.lang.tclDate : 24. Mar 2025, 04:01:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrqhus$3qsb2$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla Thunderbird
To get *text* from the clipboard using twapi, use twapi::read_clipboard_text, not twapi::read_clipboard.
As has been pointed out by others, Alexandru's issue is he is using [read_clipboard 1] which returns raw binary data in a specific encoding. The encoding itself is stored as CF_LOCALE clipboard format in the clipboard. To work correctly, the code would need to
- retrieve the encoded text using [read_clipboard 1]
- retrieve CF_LOCALE
- Map CF_LOCALE to the appropriate Tcl encoding
- Use [encoding] to decode the data into text
And even that is not guaranteed to work because the default CF_LOCALE encoding setting may not support all the Unicode characters pasted into the clipboard if the paster had used the CF_UNICODETEXT (13) format.
So either use Tcl's "clipboard get" or twapi's "read_clipboard_text". If insisting on using "read_clipboard" for whatever reason, use "read_clipboard 13" to read in UTF-16 encoding and then [encoding convertfrom unicode $clipdata].
Hope that clarifies
/Ashok
On 3/23/2025 6:22 PM, Harald Oehlmann wrote:
Am 21.03.2025 um 21:15 schrieb alexandru:
I wasn't able to respond until now.
Currently I'm happy with the workaround using "clipboard get" instead of
twapi equivalent command.
Stil one might suspect a bug in twapi. I would expect that twapi can
best handle the Windows clipboard.
TWAPI gives you more control.
But you should know what you do.
In your use case (text transmission), the native clipboard code is IMHO best suited.
If you want to do enhanced things (transmit images, whatever), use TWAPI.
Take care,
Harald