Win32::Clipboard won't place Unicode text on Clipboard by design:
CF_TEXT ... is the only format you can use to set clipboard data
This is what works for me (written based on that):
use strict; use warnings; use Win32::API 'WriteMemory'; use Encode 'encode'; Win32::API-> Import( 'kernel32', 'HGLOBAL GlobalAlloc( UINT uFlags, S +IZE_T dwBytes )' ) or die; Win32::API-> Import( 'kernel32', 'UINT_PTR GlobalLock( HGLOBAL hMem )' + ) or die; Win32::API-> Import( 'kernel32', 'BOOL GlobalUnlock( HGLOBAL hMem +)' ) or die; Win32::API-> Import( 'kernel32', 'HGLOBAL GlobalFree( HGLOBAL hMem )' + ) or die; Win32::API-> Import( 'user32', 'BOOL OpenClipboard( HWND hWndNew +Owner )' ) or die; Win32::API-> Import( 'user32', 'HANDLE SetClipboardData( UINT uFor +mat, HANDLE hMem )' ) or die; Win32::API-> Import( 'user32', 'BOOL CloseClipboard( )' ) + or die; my $str = "\x{05d0}\x{05d1}\x{05d2}"; # Alef Bet Gimel my $buf = encode( 'UTF16LE', $str ) . "\0\0"; my $h = GlobalAlloc( 2, length $buf ) or die; # GMEM_MOVEABLE my $p = GlobalLock( $h ) or die; WriteMemory( $p, $buf, length $buf ); GlobalUnlock( $h ); OpenClipboard( 0 ) or die; SetClipboardData( 13, $h ) or die; # CF_UNICODETEXT CloseClipboard() or die; GlobalFree( $h );
P.S. If your ANSI CP is 1255 (mine isn't, so I tested with another esoteric CP), and you don't mind appended newline, you could simply do this:
use Encode 'encode'; my $str = encode 'CP1255', "\x{05d0}\x{05d1}\x{05d2}"; system "echo $str| clip";
P.P.S. BTW, can anyone enlighten me, how Perl encodes argument to system, on Windows? Can this encoding be changed?
use strict; use warnings; use Encode 'encode'; my $str = encode 'CP1255', "\x{05d0}\x{05d1}\x{05d2}"; system "echo $str";
Output from Perl script still corresponds to my original CP1251.
C:\>mode con cp select=1255
Status for device CON:
----------------------
Lines: 9000
Columns: 80
Keyboard rate: 31
Keyboard delay: 1
Code page: 1255
C:\>echo אבג
אבג
C:\>perl 171116.pl
абв
In reply to Re: clipboard and unicode text (+ question in postscript)
by vr
in thread clipboard and unicode text
by Animor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |