golang-design / clipboard

📋 cross-platform clipboard package that supports accessing text and image in Go (macOS/Linux/Windows/Android/iOS)
https://golang.design/x/clipboard
MIT License
579 stars 64 forks source link

The shortcut key Ctrl+C cannot be detected when copying images. #50

Closed Esword618 closed 1 year ago

Esword618 commented 1 year ago

The platform I am using is Win11, and the go version is 1.20. When I use the shortcut keys Ctrl+C to copy images to the clipboard, the "golang. design/x/clipboard" library cannot detect clipboard changes.

package main

import (
    "context"
    "encoding/base64"
    "golang.design/x/clipboard"
    "log"
)

func main() {
    watchLocalClipboard(context.Background())
}

func watchLocalClipboard(ctx context.Context) {
    err := clipboard.Init()
    if err != nil {
        panic(err)
    }
    textCh := clipboard.Watch(ctx, clipboard.FmtText)
    imagCh := clipboard.Watch(ctx, clipboard.FmtImage)
    for {
        select {
        case <-ctx.Done():
            return
        case textData, ok := <-textCh:
            if !ok {
                return
            }
            log.Println(string(textData))
            log.Println("------------>text")
        case imageData, ok := <-imagCh:
            if !ok {
                return
            }
            //log.Println(imageData)
            // 将图片数据编码为 Base64 字符串
            base64String := base64.StdEncoding.EncodeToString(imageData)
            log.Println(base64String)
            //clipboard.Write(clipboard.FmtText, []byte(base64String))
            log.Println("------------>img")
        }
    }
}
rai62 commented 1 year ago

On Windows, use Shift+Win+s for clipping images.

I think the image path is just copied if you use Ctrl+C.

Esword618 commented 1 year ago

Okay, thank you.

changkun commented 1 year ago

As discussed above, this seems not a bug, closing.

xingcxb commented 10 months ago

在 Windows 上,用于Shift+Win+s剪切图像。

我认为如果您使用Ctrl+C.

On Windows, use Shift+Win+s for clipping images.

I think the image path is just copied if you use Ctrl+C.

In the actual system when I use ctrl+c, it only gets the filename of the image, not the full path. If it was the full path, it would also be beneficial to read this file and then process the decoding.