有模块 pygame.scrap.scrap 获取/设置剪贴板,但(在Linux上)我必须使用
pygame.scrap.get("text/plain;charset=utf-8").decode()
代替
pygame.scrap.get(pygame.SCRAP_TEXT)
,我需要先设置
pygame.scrap.init() pygame.scrap.set_mode(pygame.SCRAP_CLIPBOARD) #pygame.scrap.set_mode(pygame.SCRAP_SELECTION)
检查 ctrl+v
ctrl+v
if (event.key == pygame.K_v) and (event.mod & pygame.KMOD_CTRL):
pygame.event.get()中使用最小工作代码
import pygame # --- constants --- (UPPER_CASE_NAMES) SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 BLACK = (0, 0, 0) FPS = 25 # --- main --- pygame.init() pygame.scrap.init() pygame.scrap.set_mode(pygame.SCRAP_CLIPBOARD) #pygame.scrap.set_mode(pygame.SCRAP_SELECTION) screen = pygame.display.set_mode( (SCREEN_WIDTH, SCREEN_HEIGHT) ) # --- mainloop --- clock = pygame.time.Clock() running = True while running: # --- events --- for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: running = False elif event.key == pygame.K_v and event.mod & pygame.KMOD_CTRL: print('Clipboard:', pygame.scrap.get(pygame.SCRAP_TEXT)) print('Clipboard:', pygame.scrap.get("text/plain;charset=utf-8").decode()) for t in pygame.scrap.get_types(): r = pygame.scrap.get(t) print('>', t, r) # --- draws --- screen.fill(BLACK) pygame.display.flip() # --- FPS --- ms = clock.tick(FPS) # --- end --- pygame.quit()
您可以在 pygame repo在github上我也找到了示例
您也可以使用模块,例如 clipboard
There is module pygame.scrap to get/set clipboard but (on Linux) I had to use
instead of
And I needed to set first
You can check Ctrl+V in loop for event in pygame.event.get() with
Ctrl+V
for event in pygame.event.get()
Minimal working code:
In PyGame repo on GitHub I found also examples/scrap_clipboard.py
You may also use modules like clipboard
如果要复制剪贴板内容使用 pyperclip
pyperclip
以下是安装链接:
您可以复制/粘贴&编辑剪贴板内容
If you want to copy the clipboard content use pyperclip
here is a link for installation : pyperclip pip link
you can copy/pasted & edit clipboard content
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
有模块 pygame.scrap.scrap 获取/设置剪贴板,但(在Linux上)我必须使用
代替
,我需要先设置
检查
ctrl+v
pygame.event.get()中使用最小工作代码
您可以在 pygame repo在github上我也找到了示例
您也可以使用模块,例如 clipboard
There is module pygame.scrap to get/set clipboard but (on Linux) I had to use
instead of
And I needed to set first
You can check
Ctrl+V
in loopfor event in pygame.event.get()
withMinimal working code:
In PyGame repo on GitHub I found also examples/scrap_clipboard.py
You may also use modules like clipboard
如果要复制剪贴板内容使用
pyperclip
以下是安装链接:
您可以复制/粘贴&编辑剪贴板内容
If you want to copy the clipboard content use
pyperclip
here is a link for installation : pyperclip pip link
you can copy/pasted & edit clipboard content