本文整理汇总了Python中pykeyboard.PyKeyboard.press_key方法的典型用法代码示例。如果您正苦于以下问题:Python PyKeyboard.press_key方法的具体用法?Python PyKeyboard.press_key怎么用?Python PyKeyboard.press_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykeyboard.PyKeyboard
的用法示例。
在下文中一共展示了PyKeyboard.press_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HIDremServerProtocol
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
class HIDremServerProtocol(com.LengthPrefixedReceiver):
"""The communication protocol."""
def setup(self):
self.k = PyKeyboard()
self.m = PyMouse()
def got_message(self, msg):
"""called when a message was received."""
if not msg:
return
idb, msg = msg[0], msg[1:]
if idb == common.ID_PING:
# echo message
self.send_message(idb + msg)
elif idb == common.ID_KEYBOARD:
action, keyname = msg[0], msg[1:]
if action == common.ACTION_PRESS:
self.k.press_key(keyname)
elif action == common.ACTION_RELEASE:
self.k.release_key(keyname)
else:
# protocol violation
self.close()
elif idb == common.ID_MOUSE:
pass
else:
# protocol violation
self.close()
示例2: change_window_start
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def change_window_start():
print('*_* change_window_start')
k = PyKeyboard()
k.release_key(k.alt_key)
k.press_key(k.alt_key)
k.tap_key(k.tab_key)
示例3: Robot
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
class Robot(object):
def __init__(self):
self.mouse = PyMouse()
self.keyboard = PyKeyboard()
self.przyciskPSP2klawiatura = {'up': 'w', 'right': 'd', 'down': 's', 'left': 'a', 'triangle': self.keyboard.enter_key,
'circle': 'f', 'cross': 'g', 'square': 'h', 'l': self.keyboard.control_r_key, 'r': self.keyboard.shift_r_key, 'start': 'k', 'select': 'l'}
def reaguj(self, x, y, przyciskPSP2Stan):
self.reaguj_mysz(x, y)
self.reaguj_klawiatura(przyciskPSP2Stan)
def reaguj_mysz(self, x, y):
max_predkosc_kursora = 0.00000000000000000000000000000000000000000000000000001
x += int((x / float(128)) * max_predkosc_kursora +
self.mouse.position()[0])
y += int((y / float(128)) * max_predkosc_kursora +
self.mouse.position()[1])
x, y = min(self.mouse.screen_size()[0], x), min(
self.mouse.screen_size()[1], y)
x, y = max(0, x), max(0, y)
self.mouse.move(x, y)
def reaguj_klawiatura(self, przyciskPSP2Stan):
for przycisk_psp, czyWcisniety in przyciskPSP2Stan.iteritems():
przycisk_klawiaturowy = self.przyciskPSP2klawiatura[przycisk_psp]
if czyWcisniety == '1':
if przycisk_klawiaturowy == 'g':
self.mouse.click(*self.mouse.position())
break
self.keyboard.press_key(przycisk_klawiaturowy)
else:
self.keyboard.release_key(przycisk_klawiaturowy)
示例4: previous_focus
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def previous_focus():
print('*_* next_focus')
k = PyKeyboard()
k.press_key(k.shift_key)
k.tap_key(k.tab_key)
k.release_key(k.shift_key)
示例5: keyboard
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def keyboard(event):
if event.KeyID == 27:
key = PyKeyboard()
print "key1"
key.press_key(162) # ctrl
key.press_key(67) # c
key.release_key(67) # c
key.release_key(162) # ctrl
print "key2"
print event.KeyID
return True
示例6: key_combo
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def key_combo(key0, key1):
k = PyKeyboard()
if key0 == 'ctrl':
key0 = k.control_key
k.press_key(key0)
k.tap_key(key1)
k.release_key(key0)
示例7: sendMessage
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def sendMessage(message):
if Var.locked:
return
if not (type(message) is str):
try:
message = str(message)
except Exception:
pass
try:
message = message.encode('ascii', 'ignore')
except Exception:
message = message.encode('utf-8', 'ignore')
Var.locked = True
k = PyKeyboard()
try:
k.type_string(message)
except Exception:
k.press_key(k.control_l_key)
k.tap_key('A')
k.release_key(k.control_l_key)
k.tap_key(k.backspace_key)
k.type_string("Message Contains Unknown Characters")
k.tap_key(k.enter_key)
Var.locked = False
示例8: new_tab
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def new_tab():
print('*_* new_tab')
k = PyKeyboard()
k.release_key(k.control_l_key)
k.press_key(k.control_l_key)
k.tap_key('t')
k.release_key(k.control_l_key)
示例9: close_tab
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def close_tab():
print('*_* new_tab')
k = PyKeyboard()
k.release_key(k.control_l_key)
k.press_key(k.control_l_key)
k.tap_key(k.function_keys[4])F
k.release_key(k.control_l_key)
示例10: next_tab
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def next_tab():
print('*_* next_tab')
k = PyKeyboard()
k.press_key(k.control_l_key)
# k.press_key(k.shift_key)
k.tap_key(k.tab_key)
k.release_key(k.control_l_key)
示例11: previous_tab
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def previous_tab():
print('*_* previous_tab')
k = PyKeyboard()
k.press_key(k.control_l_key)
k.press_key(k.shift_key)
k.tap_key(k.tab_key)
k.release_key(k.control_l_key)
k.release_key(k.shift_key)
示例12: move
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def move ():
deadzone_x = 200
deadzone_y = 200
key_delay = 0.4
keyboard = PyKeyboard()
jumpPad = Button(4, pull_up=True)
PORT = "/dev/ttyACM0"
#~ PORT = "/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_9900023431864e45001210060000003700000000cc4d28bd-if01"
BAUD = 115200
s = serial.Serial(PORT)
s.baudrate = BAUD
s.parity = serial.PARITY_NONE
s.databits = serial.EIGHTBITS
s.stopbits = serial.STOPBITS_ONE
while True:
if jumpPad.is_pressed:
# It's set to pullup then shorted to ground, so we're working backwards here.
keyboard.press_key('space')
time.sleep(key_delay)
keyboard.release_key('space')
data = s.readline().decode('UTF-8')
data_list = data.rstrip().split(' ')
try:
x, y, z, a, b = data_list
if int(x) < (0 - deadzone_x) :
keyboard.press_key('a')
time.sleep(key_delay)
keyboard.release_key('a')
if int(x) > deadzone_x:
keyboard.press_key('d')
time.sleep(key_delay)
keyboard.release_key('d')
if int(y) < (0 - deadzone_y):
keyboard.press_key('w')
time.sleep(key_delay)
keyboard.release_key('w')
if int(y) > deadzone_y:
keyboard.press_key('s')
time.sleep(key_delay)
keyboard.release_key('s')
else:
keyboard.release_key('a')
keyboard.release_key('d')
keyboard.release_key('w')
keyboard.release_key('s')
#~ print(x, y, z, a, b)
except:
pass
s.close()
示例13: faceTracker
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def faceTracker():
k = PyKeyboard()
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)
centerX = 0;
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(150, 150), )
#Draw a rectangle around the faces
#for (x, y, w, h) in faces:
# cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
if len(faces) >= 1:
(x,y,w,h) = faces[0]
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
centerNew = x + w/2
if centerNew < centerX - 10:
#print "left"
k.press_key('A')
time.sleep(.2)
k.release_key('A')
if centerNew > centerX + 10:
#print "right"
k.press_key('D')
time.sleep(.2)
k.release_key('D')
centerX = centerNew
# Display the resulting frame
#cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
示例14: process_message
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def process_message(in_msg, midi_to_shortcut):
""" processes message """
keyboard = PyKeyboard()
print(in_msg)
try:
if (in_msg.note, in_msg.channel) in midi_to_shortcut and in_msg.type != 'note_off':
shortcut = midi_to_shortcut[(in_msg.note, in_msg.channel)]
print('shortcut: ', shortcut)
for key in shortcut:
keyboard.press_key(key)
for key in shortcut:
keyboard.release_key(key)
except OSError:
print('note not recognized')
示例15: type_unicode
# 需要导入模块: from pykeyboard import PyKeyboard [as 别名]
# 或者: from pykeyboard.PyKeyboard import press_key [as 别名]
def type_unicode(symbol):
k = PyKeyboard()
hexval = symbol.encode("unicode_escape")
print hexval
if hexval[:2] == '\u': # if the value is a hex number
k.press_key('Control_L') # press the control
k.press_key('Shift_L') # the left shift
k.tap_key('u') # and the u key
k.release_key('Control_L') # release the control
k.release_key('Shift_L') # and shift keys
hexval = hexval[2:] # remove the unicode escape character
k.type_string(hexval) # type the unicode string
k.tap_key('Return') # tap the return key
else: # if the given string isnt a unicode character
k.type_string(hexval) # just type the string