2010-03-04 24 views
0

我使用Perl/Tk爲應用程序構建GUI。我打算通過標準剪切,複製和粘貼選項向其添加編輯菜單。就在這裏,我意識到我從來沒有真正使用perl與剪貼板進行交互。編輯>使用perl/tk複製/粘貼實現

任何人都可以給我一個關於在perl中剪貼板搞亂信息的鏈接嗎?在特定的函數中是否有perl模塊?

如果我與剪貼板交互,我將不得不修改我的代碼,使其成爲特定於平臺的代碼,因爲它是主機操作系統的一部分,而不是我的應用程序本身的一部分?

在此先感謝您的幫助!

回答

1
use strict; 
use Win32::GuiTest qw(:ALL); 
use Win32::Clipboard; 
use POSIX qw(strftime); 

my @windows = FindWindowLike(0, "Total", ""); 
die "Could not find Total\n" if not @windows; 

SetForegroundWindow($windows[0]); 

&send_keys; 

sub send_keys { 
my $dir=strftime('%Y%m%d', localtime(time)); 
my $CLIP = Win32::Clipboard(); 
    $CLIP->Set($dir); 
    $CLIP->WaitForChange(); 
    SendKeys("^V"); 
# SendKeys("{ENTER}"); 
}