+
+
Posts List
  1. 程序描述
  2. 涉及知识点
  3. 代码

Python编程快速上手(四)多重剪贴板

程序描述

  • 当不传入参数时,程序监视并保存剪贴板内容
  • 为保存的剪贴板内容设置关键字,通过关键字可访问到保存的内容
  • ls 显示所有关键字
  • clear 清空剪贴板历史记录

涉及知识点

  • Shelve
  • pyperclip

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! python3
import pyperclip, sys, shelve

keywords = shelve.open('cp.db')

def help():
print('Usage: python filename.py ls - show all keywords')
print('Usage: python filename.py save [keyword] - save the clipboard content as keyword')
print('Usage: python filename.py [keyword] - copy the content to clipboard')
print('Usage: python filename.py clear - empty the history')
sys.exit()


if len(sys.argv) < 2:
i = 1
while True:
keywords[str(i)] = pyperclip.paste()
if pyperclip.paste() != keywords[str(i)]:
i += 1

inputstr = sys.argv[1]
if inputstr == 'ls':
for key in keywords.keys():
print(key)
elif inputstr == 'clear':
keywords.clear()
exit()
elif inputstr == 'save':
try:
inputstr2 = sys.argv[2]
keywords[inputstr2] = pyperclip.paste()
print(keywords[inputstr2])
print('CONTENT SAVED')
except:
help()
elif inputstr in keywords.keys():
print(keywords[inputstr])
pyperclip.copy(keywords[inputstr])
print('CONTENT COPIED')
else:
help()

keywords.close()

本文作者: rhinoc

本文链接: https://www.rhinoc.top/python_4/

版权声明: 本博客所有文章除特别声明外,均采用BY-NC-SA 4.0国际许可协议,转载请注明。

打赏
Love U 3000
  • Through WeChat
  • Through Alipay