def WriteClip(info):
import pyperclip
pyperclip.copy(info)
spam = pyperclip.paste()
return spam
# ================??????================
python类paste()的实例源码
def paste_from_clipboard():
text = pyperclip.paste()
return text
def copy_to_clipboard(new_text):
pyperclip.copy(new_text)
print("The new string is now copied to the clipboard. Hit CTRL V to paste.")
def paste_from_clipboard():
text = pyperclip.paste().split("\r")
return text
def copy_to_clipboard(new_list):
new_list[-1] = '\n' + new_list[-1]
new_text = ''.join(new_list)
pyperclip.copy(new_text)
print("The new string is now copied to the clipboard. Hit CTRL V to paste.")
def create_list():
input_list = pyperclip.paste().split('\n')
input_list.sort(key=float)
return input_list
def openMaps(address):
if address == "":
address = paste()
open_new_tab("http://www.google.com/maps/place/"+address)
#open a url in new tab
def get_data(self):
text = pyperclip.paste()
# When the clipboard data is equal to what we copied last time, reuse
# the `ClipboardData` instance. That way we're sure to keep the same
# `SelectionType`.
if self._data and self._data.text == text:
return self._data
# Pyperclip returned something else. Create a new `ClipboardData`
# instance.
else:
return ClipboardData(
text=text,
type=SelectionType.LINES if '\n' in text else SelectionType.LINES)
def get_data(self, key='W'):
"?CVirtualGridCtrl|Custom<n>?????????????????"
keystroke(self.two_way, ord(key)) # ?????('W')???('E')???('R')
wait_a_second() # ?????????...
op.SendMessageW(self.custom, WM_COMMAND, 57634, self.path_custom[-1]) # background mode
return pyperclip.paste()
def get_data(self):
text = pyperclip.paste()
# When the clipboard data is equal to what we copied last time, reuse
# the `ClipboardData` instance. That way we're sure to keep the same
# `SelectionType`.
if self._data and self._data.text == text:
return self._data
# Pyperclip returned something else. Create a new `ClipboardData`
# instance.
else:
return ClipboardData(
text=text,
type=SelectionType.LINES if '\n' in text else SelectionType.LINES)
def readChar():
if event.key == pygame.K_BACKSPACE:
return 'backspace'
elif event.key == pygame.K_PAGEUP:
return 'pageup'
elif event.key == pygame.K_PAGEDOWN:
return 'pagedown'
elif event.key == pygame.K_TAB:
return 'tab'
elif event.key == pygame.K_RETURN:
return 'enter'
elif event.key == pygame.K_ESCAPE:
return 'esc'
elif event.key in (pygame.K_RSHIFT, pygame.K_LSHIFT):
return 'shift'
elif event.key in (pygame.K_RCTRL, pygame.K_LCTRL):
return 'control'
elif event.key == pygame.K_RIGHT:
return 'kright'
elif event.key == pygame.K_LEFT:
return 'kleft'
elif event.key == pygame.K_UP:
return 'kup'
elif event.key == pygame.K_DOWN:
return 'kdown'
elif event.key == pygame.K_CAPSLOCK:
return None
elif event.key == 282:
return 'paste'
elif event.key == 283:
return 'begincur'
elif event.key == 284:
return 'endcur'
elif event.key == 285:
return 'delall'
else:
return event.unicode
def _redirect_output(self, statement):
"""Handles output redirection for >, >>, and |.
:param statement: ParsedString - subclass of str which also contains pyparsing ParseResults instance
"""
if statement.parsed.pipeTo:
self.kept_state = Statekeeper(self, ('stdout',))
# Create a pipe with read and write sides
read_fd, write_fd = os.pipe()
# Make sure that self.poutput() expects unicode strings in Python 3 and byte strings in Python 2
write_mode = 'w'
read_mode = 'r'
if six.PY2:
write_mode = 'wb'
read_mode = 'rb'
# Open each side of the pipe and set stdout accordingly
# noinspection PyTypeChecker
self.stdout = io.open(write_fd, write_mode)
# noinspection PyTypeChecker
subproc_stdin = io.open(read_fd, read_mode)
# We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True.
try:
self.pipe_proc = subprocess.Popen(shlex.split(statement.parsed.pipeTo), stdin=subproc_stdin)
except Exception as ex:
# Restore stdout to what it was and close the pipe
self.stdout.close()
subproc_stdin.close()
self.pipe_proc = None
self.kept_state.restore()
self.kept_state = None
# Re-raise the exception
raise ex
elif statement.parsed.output:
if (not statement.parsed.outputTo) and (not can_clip):
raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable')
self.kept_state = Statekeeper(self, ('stdout',))
self.kept_sys = Statekeeper(sys, ('stdout',))
if statement.parsed.outputTo:
mode = 'w'
if statement.parsed.output == 2 * self.redirector:
mode = 'a'
sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode)
else:
sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+")
if statement.parsed.output == '>>':
self.poutput(get_paste_buffer())