本文整理汇总了Python中pymouse.PyMouse.scroll方法的典型用法代码示例。如果您正苦于以下问题:Python PyMouse.scroll方法的具体用法?Python PyMouse.scroll怎么用?Python PyMouse.scroll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymouse.PyMouse
的用法示例。
在下文中一共展示了PyMouse.scroll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wheel
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
def wheel(ticks):
"""
Simulates a mouse wheel movement
Args:
ticks (int) : number of increments to scroll the wheel
"""
m = PyMouse()
m.scroll(ticks)
示例2:
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
tracker.update_image()
tracker.update()
# Check the tracking status
status = tracker.get_status(move)
if status == psmove.Tracker_TRACKING:
x, y, radius = tracker.get_position(move)
# print 'Position: (%5.2f, %5.2f), Radius: %3.2f, Trigger: %3d' % (
# x, y, radius, move.get_trigger())
m.move(x*3,y*3)
pressed, released = move.get_button_events()
buttons = move.get_buttons()
scrollDirection = 1 if buttons & psmove.Btn_TRIANGLE else -1
m.scroll(scrollDirection * move.get_trigger() / 20)
if pressed & psmove.Btn_MOVE:
m.click(x*3,y*3)
# elif buttons & psmove.Btn_MOVE:
# m.drag(x*3,y*3)
if pressed & psmove.Btn_SELECT:
k.tap_key(k.windows_l_key)
if pressed & psmove.Btn_CIRCLE:
m.click(x*3,y*3, 2)
if pressed & psmove.Btn_CROSS:
k.tap_key(k.enter_key)
示例3: __init__
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
class ServerMouseController:
"""
class ServerMouseController
---
This class should be able to control the mouse with the data received
from a client. It should be able to move, scroll and click. It works only
with one client.
"""
PACKET_MOVE = 1
PACKET_CLICK = 2
PACKET_SCROLL = 3
# We want only one connection for the server.
MAX_CONNECTION = 1
def __init__(self, port=34555):
print ('You should connect on', (
socket.gethostbyname_ex(socket.gethostname()), port))
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server_socket.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.mouse_controller = PyMouse()
self.server_running = True
self.host = ''
self.port = port
self.buffer = '' # array.array('b', '\0' * 512)
self.client = None
def start(self):
def handler_interupt(signum, frame):
print('interrupt server')
self.stop()
self.server_socket.bind((self.host, self.port))
self.server_socket.listen(ServerMouseController.MAX_CONNECTION)
signal.signal(signal.SIGINT, handler_interupt)
print('start server')
self.run()
def run(self):
while self.server_running:
potential_read = [self.server_socket]
if self.client is not None:
potential_read.append(self.client)
try:
ready_to_read, ready_to_write, in_erro = select.select(
potential_read, [], [])
if self.server_socket in ready_to_read:
conn, addr = self.server_socket.accept()
self.client = conn
print('New connection from ', addr)
elif self.client in ready_to_read:
# self.client.recv_into(self.buffer, 512)
recv = self.client.recv(128)
self.buffer += recv
if len(recv) == 0:
print('Disconnection from client')
self.client.close()
self.client = None
self.buffer = ''
continue
unpack = Unpacker(self.buffer)
if len(self.buffer) >= unpack.unpack_int():
unpack.set_position(0)
size = unpack.unpack_int()
cmd = unpack.unpack_int()
if cmd == ServerMouseController.PACKET_MOVE:
# Mouse move control
x = unpack.unpack_float()
y = unpack.unpack_float()
print(size, cmd, x, y)
self.mouse_controller.move(
self.mouse_controller.position()[0] - x,
self.mouse_controller.position()[1] - y)
elif cmd == ServerMouseController.PACKET_CLICK:
# Mouse click control
button = unpack.unpack_int()
nb_click = unpack.unpack_int()
print(size, cmd, button, nb_click)
self.mouse_controller.click(
self.mouse_controller.position()[0],
self.mouse_controller.position()[1],
button,
nb_click)
elif cmd == ServerMouseController.PACKET_SCROLL:
# Mouse scrolling
x = unpack.unpack_float()
y = unpack.unpack_float()
print(size, cmd, x, y)
self.mouse_controller.scroll(
vertical=int(y), horizontal=int(x))
self.buffer = self.buffer[unpack.get_position():]
except select.error as e:
print(e)
if self.client is not None:
self.client.close()
self.server_socket.close()
print('Server stop')
#.........这里部分代码省略.........
示例4: Bot
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
class Bot():
def __init__(self):
self.mouse = PyMouse()
self.keyboard = PyKeyboard()
def Delay(self, n):
time.sleep(n)
""" ====== Mouse Macro ====== """
def Left_click(self, x, y, n = 1, dl = 0):
"""在屏幕某点左键点击若干次
"""
self.Delay(dl)
self.mouse.click(x, y, 1, n)
def Right_click(self, x, y, n = 1, dl = 0):
"""在屏幕某点右键点击若干次
"""
self.Delay(dl)
self.mouse.click(x, y, 2, n)
def Double_click(self, x, y, dl = 0):
"""在屏幕的某点双击
"""
self.Delay(dl)
self.mouse.click(x, y, 1, n = 2)
def Scroll_up(self, n, dl = 0):
"""鼠标滚轮向上n次
"""
self.Delay(dl)
self.mouse.scroll(vertical = n)
def Scroll_down(self, n, dl = 0):
"""鼠标滚轮向下n次
"""
self.Delay(dl)
self.mouse.scroll(vertical = -n)
def Move_to(self, x, y, dl = 0):
"""鼠标移动到x, y的坐标处
"""
self.Delay(dl)
self.mouse.move(x, y)
def Drag_and_release(self, start, end, dl = 0):
"""从start的坐标处鼠标左键单击拖曳到end的坐标处
start, end是tuple. 格式是(x, y)
"""
self.Delay(dl)
self.mouse.press(start[0], start[1], 1)
self.mouse.drag(end[0], end[1])
self.Delay(0.1)
self.mouse.release(end[0], end[1], 1)
def Screen_size(self):
width, height = self.mouse.screen_size()
return width, height
def WhereXY(self):
x_axis, y_axis = self.mouse.position()
return x_axis, y_axis
""" ====== Keyboard Macro ====== """
"""COMBINATION组合键"""
"""Ctrl系列"""
def Ctrl_c(self, dl = 0):
"""Ctrl + c 复制
"""
self.Delay(dl)
self.keyboard.press_key(self.keyboard.control_key)
self.keyboard.tap_key("c")
self.keyboard.release_key(self.keyboard.control_key)
def Ctrl_x(self, dl = 0):
"""Ctrl + x 剪切
"""
self.Delay(dl)
self.keyboard.press_key(self.keyboard.control_key)
self.keyboard.tap_key("x")
self.keyboard.release_key(self.keyboard.control_key)
def Ctrl_v(self, dl = 0):
"""Ctrl + v 粘贴
"""
self.Delay(dl)
self.keyboard.press_key(self.keyboard.control_key)
self.keyboard.tap_key("v")
self.keyboard.release_key(self.keyboard.control_key)
def Ctrl_z(self, dl = 0):
"""Ctrl + z 撤销上一次操作
"""
self.Delay(dl)
self.keyboard.press_key(self.keyboard.control_key)
self.keyboard.tap_key("z")
self.keyboard.release_key(self.keyboard.control_key)
def Ctrl_y(self, dl = 0):
#.........这里部分代码省略.........
示例5: ControlMainClass
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
#.........这里部分代码省略.........
self.keyboardMap[76] = self.pyKeyboard.alt_r_key
self.keyboardMap[78] = self.pyKeyboard.backspace_key
self.keyboardMap[90] = self.pyKeyboard.control_l_key
self.keyboardMap[91] = self.pyKeyboard.control_r_key
self.keyboardMap[93] = self.pyKeyboard.delete_key
self.keyboardMap[94] = self.pyKeyboard.delete_key
self.keyboardMap[96] = self.pyKeyboard.down_key
self.keyboardMap[97] = self.pyKeyboard.end_key
self.keyboardMap[98] = self.pyKeyboard.enter_key
self.keyboardMap[99] = self.pyKeyboard.escape_key
self.keyboardMap[102] = self.pyKeyboard.function_keys[1]
self.keyboardMap[103] = self.pyKeyboard.function_keys[10]
self.keyboardMap[104] = self.pyKeyboard.function_keys[11]
self.keyboardMap[105] = self.pyKeyboard.function_keys[12]
self.keyboardMap[113] = self.pyKeyboard.function_keys[2]
self.keyboardMap[119] = self.pyKeyboard.function_keys[3]
self.keyboardMap[120] = self.pyKeyboard.function_keys[4]
self.keyboardMap[121] = self.pyKeyboard.function_keys[5]
self.keyboardMap[122] = self.pyKeyboard.function_keys[6]
self.keyboardMap[123] = self.pyKeyboard.function_keys[7]
self.keyboardMap[124] = self.pyKeyboard.function_keys[8]
self.keyboardMap[125] = self.pyKeyboard.function_keys[9]
if self.osName=="Windows":
self.keyboardMap[129] = self.pyKeyboard.hangul_key
elif self.osName=="Linux":
self.keyboardMap[129] = -1
pass
self.keyboardMap[132] = self.pyKeyboard.home_key
self.keyboardMap[141] = self.pyKeyboard.left_key
self.keyboardMap[146] = '0'
self.keyboardMap[147] = '1'
self.keyboardMap[148] = '2'
self.keyboardMap[149] = '3'
self.keyboardMap[150] = '4'
self.keyboardMap[151] = '5'
self.keyboardMap[152] = '6'
self.keyboardMap[153] = '7'
self.keyboardMap[154] = '8'
self.keyboardMap[155] = '9'
self.keyboardMap[156] = self.pyKeyboard.num_lock_key
self.keyboardMap[157] = self.pyKeyboard.page_down_key
self.keyboardMap[158] = self.pyKeyboard.page_up_key
self.keyboardMap[160] = self.pyKeyboard.page_down_key
self.keyboardMap[161] = self.pyKeyboard.page_up_key
self.keyboardMap[170] = self.pyKeyboard.right_key
self.keyboardMap[171] = self.pyKeyboard.scroll_lock_key
self.keyboardMap[175] = self.pyKeyboard.shift_l_key
self.keyboardMap[176] = self.pyKeyboard.shift_r_key
self.keyboardMap[180] = self.pyKeyboard.tab_key
self.keyboardMap[181] = self.pyKeyboard.up_key
pass
def command(self,data):
if data[0] == 'm':
x = (ord(data[3])*100)+ord(data[4])
y = (ord(data[5])*100)+ord(data[6])
#print "x:",x," y:",y
#self.controller.moveTo( x, y) # x,y
self.pyMouse.move(x, y)
if data[1] == 'p':
#self.controller.mouseDown(x,y,self.mouseMap[ord(data[2])]) # x,y,b
#print "press"
self.pyMouse.press(x, y,ord(data[2]))
pass
elif data[1] == 'r' and ord(data[2]) != 0:
#self.controller.mouseUp(x,y,self.mouseMap[ord(data[2])]) # x,y,b
#print "release"
self.pyMouse.release(x, y, ord(data[2]))
pass
if data[7] == 's':
if data[8] == 'u':
#self.controller.scroll(10)
self.pyMouse.scroll(vertical=10)
pass
else:
#self.controller.scroll(-10)
self.pyMouse.scroll(vertical=-10)
pass
pass
else:
print 'data: ',data[0],' '+data[1],' ',ord(data[2])
keyCode=ord(data[2])
if data[1]=='p' and keyCode!=0:
#self.controller.keyDown(self.controller.KEYBOARD_KEYS[ord(data[2])])
print 'press '+str(ord(data[2]))
if self.keyboardMap[ord(data[2])]!=-1:
self.pyKeyboard.press_key(self.keyboardMap[ord(data[2])])
pass
elif data[1]=='r' and keyCode!=0:
#self.controller.keyUp(self.controller.KEYBOARD_KEYS[ord(data[2])])
print 'release '+str(ord(data[2]))
if self.keyboardMap[ord(data[2])]!=-1:
self.pyKeyboard.release_key(self.keyboardMap[ord(data[2])])
pass
pass
示例6: Bot
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
#.........这里部分代码省略.........
**中文文档**
在屏幕的 ``(x, y)`` 坐标处左键单击 ``n`` 次。
"""
self.delay(pre_dl)
self.m.click(x, y, 1, n)
self.delay(post_dl)
def right_click(self, x, y, n=1, pre_dl=None, post_dl=None):
"""Right click at ``(x, y)`` on screen for ``n`` times.
at begin.
**中文文档**
在屏幕的 ``(x, y)`` 坐标处右键单击 ``n`` 次。
"""
self.delay(pre_dl)
self.m.click(x, y, 2, n)
self.delay(post_dl)
def middle_click(self, x, y, n=1, pre_dl=None, post_dl=None):
"""Middle click at ``(x, y)`` on screen for ``n`` times.
at begin.
**中文文档**
在屏幕的 ``(x, y)`` 坐标处中键单击 ``n`` 次。
"""
self.delay(pre_dl)
self.m.click(x, y, 3, n)
self.delay(post_dl)
def scroll_up(self, n, pre_dl=None, post_dl=None):
"""Scroll up ``n`` times.
**中文文档**
鼠标滚轮向上滚动n次。
"""
self.delay(pre_dl)
self.m.scroll(vertical=n)
self.delay(post_dl)
def scroll_down(self, n, pre_dl=None, post_dl=None):
"""Scroll down ``n`` times.
**中文文档**
鼠标滚轮向下滚动n次。
"""
self.delay(pre_dl)
self.m.scroll(vertical=-n)
self.delay(post_dl)
def scroll_right(self, n, pre_dl=None, post_dl=None):
"""Scroll right ``n`` times.
**中文文档**
鼠标滚轮向右滚动n次(如果可能的话)。
"""
self.delay(pre_dl)
self.m.scroll(horizontal=n)
self.delay(post_dl)
示例7: ord
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
right = ord(data[5]) & 1 != 0
scroll = ord(data[5]) & 4 != 0
if leftPressed != left:
leftPressed = left
if left:
m.press(position[0], position[1], 1)
else:
m.release(position[0], position[1], 1)
if rightPressed != right:
rightPressed = right
if right:
m.press(position[0], position[1], 2)
else:
m.release(position[0], position[1], 2)
if not scroll and (movement[0] != 0 or movement[1] != 0):
m.move(position[0] + movement[0], position[1] + movement[1])
elif scroll:
if movement[1] >= 0:
m.scroll(position[0], position[1], False, movement[1])
else:
m.scroll(position[0], position[1], True, -movement[1])
except IOError:
pass
print "disconnected"
client_sock.close()
server_sock.close()
print "all done"
示例8: BaseCursorListener
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
#.........这里部分代码省略.........
hand_state = data['leap_state']['current']
hand_state_prev = data['leap_state']['prev']
current_time = time.time()
elapsed_time = current_time - self.press_dtstart
if hand_state.av_fingers <= 1.2:
if hand_state.av_numhands == 1 and hand_state.is_horizontal and ((hand_state_prev.av_fingers >= 3 and hand_state.av_fingers <= 1.2)
or (self.active_fist and hand_state.av_fingers < 1)):
self.press_requested = True
elif hand_state.av_numhands == 1 and hand_state.av_fingers <= 1.2 and self.press_requested == True and (elapsed_time * 1000) >= self.press_timeout:
self.active_fist = True
return True
else:
self.press_dtstart = time.time()
self.press_requested = False
return False
def is_releasing(self, data):
"""
Determines whether the mouse is releasing or not.
The default behabior is to cause a release action when the hand is not closed.
"""
# Get the required data
hand_state = data['leap_state']['current']
hand_state_prev = data['leap_state']['prev']
if hand_state.av_fingers >= 2.5 and hand_state.av_palm_pos[2] < 0 and self.active_fist:
self.active_fist = False
self.want_press = False
return True
return False
def is_scrolling_up(self, data):
"""
Determines whether the mouse is scrolling up or not.
"""
# Get the required data
hand_state = data['leap_state']['current']
if hand_state.av_fingers >= 4 and not self.active_fist and not self.press_requested:
if hand_state.av_fingers_speed - hand_state.av_palm_vel < -150:
repeats = abs(int(hand_state.av_fingers_speed / 50.))
repeats = max(repeats, 0)
repeats = min(repeats, 5)
return repeats
return False
def is_scrolling_down(self, data):
"""
Determines whether the mouse is scrolling down or not.
"""
# Get the required data
hand_state = data['leap_state']['current']
if hand_state.av_fingers >= 4 and not self.active_fist and not self.press_requested:
if hand_state.av_fingers_speed -hand_state.av_palm_vel > 150:
repeats = abs(int(hand_state.av_fingers_speed / 50.))
repeats = max(repeats, 0)
repeats = min(repeats, 5)
return repeats
return False
def is_switching_desktop(self, latest_frame):
"""
Determines whether a desktop switch must be induced or not.
示例9: command
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
#.........这里部分代码省略.........
k.tap_key(k.enter_key)
return True
if h.check_adj_lemma("new") and h.check_noun_lemma("tab"):
with nostdout():
with nostderr():
k = PyKeyboard()
k.press_keys([k.control_l_key, 't'])
return True
if h.check_verb_lemma("switch") and h.check_noun_lemma("tab"):
with nostdout():
with nostderr():
k = PyKeyboard()
k.press_keys([k.control_l_key, k.tab_key])
return True
if h.directly_equal(["CLOSE", "ESCAPE"]):
with nostdout():
with nostderr():
k = PyKeyboard()
k.press_keys([k.control_l_key, 'w'])
k.tap_key(k.escape_key)
return True
if h.check_lemma("back") and h.max_word_count(4):
with nostdout():
with nostderr():
k = PyKeyboard()
k.press_keys([k.alt_l_key, k.left_key])
return True
if h.check_lemma("forward") and h.max_word_count(4):
with nostdout():
with nostderr():
k = PyKeyboard()
k.press_keys([k.alt_l_key, k.right_key])
return True
if h.check_text("swipe") or h.check_text("scroll"):
if h.check_text("left"):
with nostdout():
with nostderr():
m = PyMouse()
m.scroll(0, -5)
return True
if h.check_text("right"):
with nostdout():
with nostderr():
m = PyMouse()
m.scroll(0, 5)
return True
if h.check_text("up"):
with nostdout():
with nostderr():
m = PyMouse()
m.scroll(5, 0)
return True
if h.check_text("down"):
with nostdout():
with nostderr():
m = PyMouse()
m.scroll(-5, 0)
return True
if h.directly_equal(["PLAY", "PAUSE", "SPACEBAR"]):
with nostdout():
with nostderr():
k = PyKeyboard()
k.tap_key(" ")
return True
if ((h.check_text("shut") and h.check_text("down")) or (h.check_text("power") and h.check_text("off"))) and h.check_text("computer"):
userin.execute(["sudo", "poweroff"], "Shutting down", True, 3)
示例10: command
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import scroll [as 别名]
#.........这里部分代码省略.........
k = PyKeyboard()
if not self.testing:
k.press_keys([k.control_l_key, 't'])
return "new tab"
if h.check_verb_lemma("switch") and h.check_noun_lemma("tab") and not args["server"]:
with nostdout():
with nostderr():
k = PyKeyboard()
if not self.testing:
k.press_keys([k.control_l_key, k.tab_key])
return "switch tab"
if h.directly_equal(["CLOSE", "ESCAPE"]) and not args["server"]:
with nostdout():
with nostderr():
k = PyKeyboard()
if not self.testing:
k.press_keys([k.control_l_key, 'w'])
k.tap_key(k.escape_key)
return "close"
if h.check_lemma("back") and h.max_word_count(4) and not args["server"]:
with nostdout():
with nostderr():
k = PyKeyboard()
if not self.testing:
k.press_keys([k.alt_l_key, k.left_key])
return "back"
if h.check_lemma("forward") and h.max_word_count(4) and not args["server"]:
with nostdout():
with nostderr():
k = PyKeyboard()
if not self.testing:
k.press_keys([k.alt_l_key, k.right_key])
return "forward"
if (h.check_text("swipe") or h.check_text("scroll")) and not args["server"]:
if h.check_text("left"):
with nostdout():
with nostderr():
m = PyMouse()
if not self.testing:
m.scroll(0, -5)
return "swipe left"
if h.check_text("right"):
with nostdout():
with nostderr():
m = PyMouse()
if not self.testing:
m.scroll(0, 5)
return "swipe right"
if h.check_text("up"):
with nostdout():
with nostderr():
m = PyMouse()
if not self.testing:
m.scroll(5, 0)
return "swipe up"
if h.check_text("down"):
with nostdout():
with nostderr():
m = PyMouse()
if not self.testing:
m.scroll(-5, 0)
return "swipe down"
if h.directly_equal(["PLAY", "PAUSE", "SPACEBAR"]) and not args["server"]:
with nostdout():
with nostderr():
k = PyKeyboard()