Skip to main content

Clipboard

Examples#

Basic#

examples/unit/clipboard/clipboard-basic.ts

This example shows how to read from clipboard:

clipboard basic

export function main(window: Window) {    const clipboard = AveGetClipboard();
    const button = new Button(window);    button.SetText('Inspect Clipboard');    button.OnClick((sender) => {        if (clipboard.HasImage()) {            const aveImage = clipboard.GetImage();            const imageData = aveImage.GetImage(0, 0, 0);            console.log(                `image found! width: ${imageData.Width} height: ${imageData.Height}`,            );        } else if (clipboard.HasFile()) {            const [file] = clipboard.GetFile();            console.log(`file found! path: ${file}`);        } else {            console.log(`nothing found in clipboard`);        }    });
    const container = getControlDemoContainer(window);    container.ControlAdd(button).SetGrid(1, 1);    window.SetContent(container);}

When the clipboard is empty, inspect it(press button), you will get this in console:

nothing found in clipboard

After you copy image to clipboard:

# something like this:image found! width: 413 height: 169

After you copy file:

file found! path: D:\GitHub\docs\xxx

API#

// get global clipboard instanceexport function AveGetClipboard(): IClipboard;
export interface IClipboard {    SetImage(img: AveImage): boolean;    GetImage(): AveImage;    HasImage(): boolean;
    SetFile(file: string[]): boolean;    GetFile(): string[]; // return file paths    HasFile(): boolean;}