ironpython_clipboard.py 862 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. # *****************************************************************************
  3. # Copyright (C) 2006-2020 Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
  4. # Copyright (C) 2020 Bassem Girgis. <brgirgis@gmail.com>
  5. #
  6. # Distributed under the terms of the BSD License. The full license is in
  7. # the file COPYING, distributed as part of this software.
  8. # *****************************************************************************
  9. import clr
  10. import System.Windows.Forms.Clipboard as cb
  11. clr.AddReferenceByPartialName("System.Windows.Forms")
  12. def get_clipboard_text() -> str:
  13. text = ""
  14. if cb.ContainsText():
  15. text = cb.GetText()
  16. return text
  17. def set_clipboard_text(text: str) -> None:
  18. cb.SetText(text)
  19. if __name__ == "__main__":
  20. txt = get_clipboard_text() # display last text clipped
  21. print(txt)