package clipboard import ( "b612.me/win32api" "encoding/binary" "fmt" "os" "syscall" "testing" "time" ) func TestGet(t *testing.T) { fmt.Println(win32api.RegisterClipboardFormat("Preferred DropEffect")) lsn, err := Listen(false) if err != nil { t.Fatal(err) } for { select { case cb := <-lsn: fmt.Println(cb.plateform) fmt.Println(cb.winOriginTypes) fmt.Println(cb.AvailableTypes()) if cb.IsText() { fmt.Println(cb.Text()) } if cb.IsHTML() { fmt.Println(cb.HTML()) } if cb.IsFile() { fmt.Println(cb.FilePaths()) } case <-time.After(60 * time.Second): fmt.Println("not get clipboard data in 60s") StopListen() time.Sleep(time.Second * 15) return } } } func TestGetMeta(t *testing.T) { fmt.Println(win32api.RegisterClipboardFormat("Preferred DropEffect")) lsn, err := Listen(true) if err != nil { t.Fatal(err) } for { select { case cb := <-lsn: fmt.Println(cb.plateform) fmt.Println(cb.winOriginTypes) fmt.Println(cb.AvailableTypes()) fmt.Println(cb.primarySize) fmt.Println(cb.secondarySize) case <-time.After(60 * time.Second): fmt.Println("not get clipboard data in 60s") StopListen() time.Sleep(time.Second * 15) return } } } func TestAutoSetter(t *testing.T) { //samp := "天狼星、测试,123.hello.love.what??" /* err := AutoSetter("File", []string{"C:\\Users\\Starainrt\\Desktop\\haruhi.jpg"}) if err != nil { t.Fatal(err) } */ f, err := os.ReadFile("C:\\Users\\Starainrt\\Desktop\\60.png") if err != nil { t.Fatal(err) } err = AutoSetter("Image", f) if err != nil { t.Fatal(err) } } func TestSetTextOrigin(t *testing.T) { samp := "天狼星、测试,123.hello.love.what" u, err := syscall.UTF16FromString(samp) if err != nil { t.Fatal(err) } b := make([]byte, 2*len(u)) for i, v := range u { binary.LittleEndian.PutUint16(b[i*2:], v) } err = setClipboardData(win32api.CF_UNICODETEXT, b, nil) if err != nil { t.Fatal(err) } }