win32_clipboard 1.0.0 copy "win32_clipboard: ^1.0.0" to clipboard
win32_clipboard: ^1.0.0 copied to clipboard

A package that provides a friendly Dart API for accessing the Windows Clipboard.

ci Package: win32_clipboard Publisher: halildurmus.dev Language: Dart License: BSD-3-Clause codecov

A package that provides a friendly Dart API for accessing the Windows Clipboard.

This package builds on top of the Dart win32 package, offering a high-level Dart wrapper that avoids the need for users to understand FFI or write directly to the Win32 API.

Features #

  • Text Operations: Easily read and write text to the clipboard.
  • File List Operations: Easily read and write file lists to the clipboard.
  • Format Inspection: Check available formats on the clipboard.
  • Custom Formats: Register custom clipboard formats.
  • Clipboard Change Notifications: Monitor changes to the clipboard contents.
  • Clear Clipboard: Clear the clipboard contents.

To learn more, see the API Documentation.

Usage #

Text operations #

import 'package:win32_clipboard/win32_clipboard.dart';

void main() {
  if (Clipboard.setText('Hello, world!')) {
    print('Retrieved text from clipboard: "${Clipboard.getText()}"');
  }
}

File list operations #

import 'package:win32_clipboard/win32_clipboard.dart';

void main() {
  if (Clipboard.setFileList([r'c:\src\file1.dart', r'd:\file2.txt'])) {
    print('Retrieved file list from clipboard: ${Clipboard.getFileList()}');
  }
}

Listen for clipboard text changes #

import 'package:win32_clipboard/win32_clipboard.dart';

void main() async {
  // Subscribe to the clipboard text change stream.
  final subscription = Clipboard.onTextChanged.listen((text) {
    print('Clipboard text changed: "$text"');
  }, cancelOnError: true);

  print('Monitoring clipboard text changes for 30 seconds...');
  // Now, copy some text to the clipboard to see the changes.

  // Stop monitoring after 30 seconds.
  await Future.delayed(const Duration(seconds: 30), () async {
    await subscription.cancel();
    print('Stopped monitoring.');
  });
}

Retrieve a list of available clipboard formats #

import 'package:win32_clipboard/win32_clipboard.dart';

void main() {
  print('Clipboard has ${Clipboard.numberOfFormats} format(s)');
  for (final format in Clipboard.formats) {
    print('- $format');
  }
}

Clear the clipboard #

import 'package:win32_clipboard/win32_clipboard.dart';

void main() {
  if (Clipboard.clear()) {
    print('Clipboard contents cleared.');
  }
}

Feature requests and bugs #

Please file feature requests and bugs at the issue tracker.

11
likes
160
points
99
downloads

Publisher

verified publisherhalildurmus.dev

Weekly Downloads

A package that provides a friendly Dart API for accessing the Windows Clipboard.

Repository (GitHub)
View/report issues
Contributing

Topics

#clipboard #win32 #ffi #windows

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

ffi, meta, win32

More

Packages that depend on win32_clipboard