本文整理汇总了Python中pykeyboard.PyKeyboard类的典型用法代码示例。如果您正苦于以下问题:Python PyKeyboard类的具体用法?Python PyKeyboard怎么用?Python PyKeyboard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyKeyboard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Keyboard
class Keyboard(object):
def __init__(self):
super(Keyboard, self).__init__()
self.k = PyKeyboard()
def write(self,text):
self.k.type_string(text)
示例2: HIDremServerProtocol
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()
示例3: combo
def combo(*arg):
theCombo = arg[:-1]
theVelocity = arg[-1] # not used
k = PyKeyboard()
k.press_keys(theCombo)
示例4: typeString
def typeString(s):
#m = PyMouse()
k = PyKeyboard()
#print args
#k.press_keys(args)
k.type_string(s)
示例5: on_End_combo
def on_End_combo():
logging.info(30*'_' + " on_End_combo")
k = PyKeyboard()
#抬起功能按键Ctrl,否则End效果会变为Ctrl+End效果
k.release_key(k.control_key)
k.press_keys([k.end_key, ';', k.enter_key])
return False
示例6: on_End_analog
def on_End_analog():
logging.info(30*'_' + " on_End_analog")
k = PyKeyboard()
#抬起功能按键Ctrl,否则End效果会变为Ctrl+End效果
k.release_key(k.control_key)
k.tap_key(k.end_key)
return False
示例7: faceTracker
def faceTracker():
print "Face Track running"
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 face
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.tap_key('Left')
if centerNew < centerX - 10:
print('right')
k.tap_key('Right')
centerX = centerNew
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
示例8: switch_to_highlayer
def switch_to_highlayer(outName, frameNumber, segNumber):
#totalIdx = len(inputList)
'''
timeInterval defines the print frequency of the frame number in the terminal.
'''
timeInterval = 0.4
frameStep = timeInterval*25
k = PyKeyboard()
logName = outName + ".log"
tmpIdx = 1
while True:
text = subprocess.check_output(["tail", "-1", logName])
#tmpIdx = totalIdx - len(inputList)+1
if "PAUSE" in text and "===== PAUSE =====\rV:" not in text:
sleep(timeInterval)
continue
elif "Exiting" in text:
break
else:
print text
sleep(timeInterval)
frameIdx = parse_frame_idx(text)
if frameIdx >= frameNumber*tmpIdx and frameIdx < frameNumber*tmpIdx + frameStep:
print "======================================"
print "currentFrame is: "+str(frameIdx)+".\n"
if bool(stepList):
tmpIdx = tmpIdx +1
value = stepList.pop(0)
if value >0:
for t in range(value):
k.tap_key('b')
print "switch to higher layer"
sleep(0.1)
else:
break
示例9: xdomenu
def xdomenu():
"""interacts with a simple menu."""
char_to_bin = {'s': 'srmenu',
'j': 'jmenu',
'c': 'clipmenu',
't': 'terminal',
'u': 'urxvt',
'p': 'pomodoro',
' ': 'moveempty'}
keybrd = PyKeyboard()
k_menu = keybrd.menu_key
persistent = False
print_menu(persistent)
while True:
sleep(0.1)
stdout.flush()
char = getchar()
try:
cmd = char_to_bin[char]
print_flush(cmd)
if persistent:
sleep(0.2)
keybrd.tap_key(k_menu)
except KeyError:
if char == '\t':
persistent = not persistent
print_menu(persistent)
else:
keybrd.tap_key(k_menu)
示例10: Robot
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)
示例11: KLKeyboard
class KLKeyboard(object):
def __init__(self):
self.keyboard = PyKeyboard()
pass
def hitKey(self, key):
self.keyboard.tap_key(key)
示例12: type_msg
def type_msg(string):
"""
Stimulates typing a string of characters
Args:
string (str) : A string of characters to enter
"""
k = PyKeyboard()
k.type_string(string)
示例13: run
def run(self):
# Set up the keyboard sim
K = PyKeyboard()
# Let the program start running
# Run till it's over.
if self.lines:
for i in lines:
K.type_string(str(i))
示例14: keypress
def keypress(key):
"""
Simulates a key press
Args:
key (str) : the key [a-zA-Z0-9] to enter. Use 'enter' for the
return key
"""
k = PyKeyboard()
if key == 'enter':
key = k.return_key
k.tap_key(key)
示例15: callSequence
def callSequence(*args):
m = PyMouse()
k = PyKeyboard()
print args
#k.press_keys(args)
#k.type_string(args[0])
keys = ["cmd", "a"]
#callArray(keys)
k.press_keys(keys)