本文整理汇总了Python中pymouse.PyMouse类的典型用法代码示例。如果您正苦于以下问题:Python PyMouse类的具体用法?Python PyMouse怎么用?Python PyMouse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyMouse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouse_simulate
def mouse_simulate():
try:
class event(PyMouseEvent):
def move(self, x, y):
pass
def click(self, x, y, button, press):
if press:
print("Mouse pressed at", x, y, "with button", button)
else:
print("Mouse released at", x, y, "with button", button)
e = event()
e.start()
except ImportError:
print("Mouse events are not yet supported on your platform")
m = PyMouse()
t_corr = (1173,313)
i_pos = t_corr
m.move(i_pos[0] , i_pos[1])
while(True):
if is_run is False:
time.sleep(1)
else:
time.sleep(0.2)
m.click(i_pos[0], i_pos[1])
try:
e.stop()
except:
pass
示例2: move
def move ():
deadzone_x = 200
deadzone_y = 200
key_delay = 0.4
mouse = PyMouse()
PORT = "/dev/ttyACM1"
#~ 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:
data = s.readline().decode('UTF-8')
data_list = data.rstrip().split(' ')
try:
x, y, z, a, b = data_list
x_mapped = arduino_map(int(x), -1024, 1024, -960, 960)
y_mapped = arduino_map(int(y), -1024, 1024, -540, 540)
x_centre = 960
y_centre = 540
print(x_mapped, y_mapped)
mouse.move(x_centre + x_mapped, y_centre + y_mapped)
except:
pass
s.close()
示例3: test_move
def test_move(self):
for size in screen_sizes:
with Display(visible=VISIBLE, size=size):
mouse = PyMouse()
for p in positions:
mouse.move(*p)
eq_(expect_pos(p, size), mouse.position())
示例4: click
def click(pos):
'''
pos: (x, y) # (0, 0) for top left piece
'''
m = PyMouse()
m.click(RECT[0] + PIECE_X / 2 + PIECE_X * pos[0], RECT[1] + PIECE_Y / 2 + PIECE_Y * pos[1])
time.sleep(0.5)
示例5: showMouseLoc
def showMouseLoc(self):
try:
m = PyMouse() # make mouse object
while(1):
print m.position() # print the position
except KeyboardInterrupt:
pass
示例6: move_down
def move_down():
m = PyMouse()
xt=random.randint(1400, 1600)
yt=random.randint(700, 800)
m.position()
m.move(xt, yt)
示例7: __init__
class Mouse:
def __init__(self):
import autopy
from pymouse import PyMouse
self.m1 = autopy.mouse
self.loc = [self.m1.get_pos()[0],self.m1.get_pos()[1]]
self.m = PyMouse()
self.m.move(self.loc[0], self.loc[1])
def move(self,direction):
#Move mouse
self.loc[0] += direction[0]
self.loc[1] += direction[1]
#FIXME: Support multiple displays
#Check horizontal bounds
self.loc[0] = min(self.loc[0],3600)#self.m.screen_size()[0])
self.loc[0] = max(self.loc[0],0)
#Check vertical bounds
self.loc[1] = min(self.loc[1],self.m.screen_size()[1])
self.loc[1] = max(self.loc[1],0)
self.m.move(int(self.loc[0]), int(self.loc[1]))
def click(self,button):
self.m1.click(button)
示例8: main
def main():
mouse = PyMouse()
# wm = cwiid.Wiimote("00:25:A0:CE:3B:6D")
wm = cwiid.Wiimote()
wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR
X, x = calibrate(wm)
trans = getTransMatrix(x, X)
screen = mouse.screen_size()
lastTime = time.time()
o = None
state = NEUTRAL
print("battery: %f%%" % (float(wm.state["battery"]) / float(cwiid.BATTERY_MAX) * 100.0))
window = pygame.display.set_mode((200, 150))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
pos = getWiiPointNonBlock(wm)
if pos != None:
ipt = numpy.matrix([[pos.x], [pos.y], [1]])
optMat = trans.I * ipt
o = Point(optMat[0] / optMat[2], optMat[1] / optMat[2])
if o.x < 0:
o.x = 0
elif o.x >= screen[0]:
o.x = screen[0] - 1
if o.y < 0:
o.y = 0
elif o.y >= screen[1]:
o.y = screen[1] - 1
if state == NEUTRAL:
state = FIRST_INPUT
lastTime = time.time()
elif state == FIRST_INPUT:
if time.time() - FIRST_INPUT_TO_PRESSED > lastTime:
mouse.press(o.x, o.y)
state = PRESSED
elif state == PRESSED:
mouse.move(o.x, o.y)
if state == FIRST_INPUT and pos == None and time.time() - FIRST_INPUT_TO_PRESSED < lastTime:
mouse.click(o.x, o.y)
time.sleep(0.2)
state = NEUTRAL
if state == PRESSED and pos == None and time.time() - 1 > lastTime:
mouse.release(o.x, o.y)
state = NEUTRAL
示例9: draw_arc
def draw_arc(self, window):
#self.drawing_area.window.draw_arc(self.context, False, self._x, self._y, 70, 70, 0, 360*64)
window.set_keep_below(True)
window.hide()
m = PyMouse()
m.move(self._x, self._y)
m.click(self._x, self._y, 1)
示例10: run
def run(self):
global mself
global runflag
m = PyMouse()
#raw_input("请先将鼠标移动到数据位置的左上角,然后按下回车.")
wx.MessageBox("请不要点击该对话框的确定按钮\n先将鼠标移动到数据位置的左上角,然后按下回车...", "获取数据位置", wx.OK)
p1 = m.position()
print p1
#raw_input("接下来将鼠标移动到数据位置的右下角,然后按下回车.")
wx.MessageBox("接下来将鼠标移动到数据位置的右下角,然后按下回车...", "获取数据位置", wx.OK)
p2 = m.position()
print p2
print "完成数据位设定,开始获取数据工作."
imbox = (p1[0], p1[1], p2[0], p2[1])
prev_s = [0,0,0,0]
while runflag:
try:
im = ImageGrab.grab(imbox)
s = image_to_string(im)
s = s.split()
if s != prev_s and len(s)==4 :
sell = float(s[0]) - float(prev_s[0])
buy = float(s[2]) - float(prev_s[2])
prev_s = s
print sell, buy
mself.staticText1.SetLabel(mself.staticText2.GetLabel())
mself.staticText2.SetLabel(mself.staticText3.GetLabel())
mself.staticText3.SetLabel(mself.staticText4.GetLabel())
mself.staticText4.SetLabel(mself.staticText5.GetLabel())
mself.staticText5.SetLabel(mself.staticText6.GetLabel())
mself.staticText6.SetLabel(mself.staticText7.GetLabel())
mself.staticText7.SetLabel(mself.staticText8.GetLabel())
mself.staticText8.SetLabel(mself.staticText9.GetLabel())
mself.staticText9.SetLabel(mself.staticText10.GetLabel())
mself.staticText10.SetLabel("%.1f"%sell)
mself.staticText11.SetLabel(mself.staticText12.GetLabel())
mself.staticText12.SetLabel(mself.staticText13.GetLabel())
mself.staticText13.SetLabel(mself.staticText14.GetLabel())
mself.staticText14.SetLabel(mself.staticText15.GetLabel())
mself.staticText15.SetLabel(mself.staticText16.GetLabel())
mself.staticText16.SetLabel(mself.staticText17.GetLabel())
mself.staticText17.SetLabel(mself.staticText18.GetLabel())
mself.staticText18.SetLabel(mself.staticText19.GetLabel())
mself.staticText19.SetLabel(mself.staticText20.GetLabel())
mself.staticText20.SetLabel("%.1f"%buy)
im.save("show.jpg")
pic=wx.Image("show.jpg")
w,h = mself.staticBitmap1.GetSize()
mself.staticBitmap1.SetBitmap(pic.Rescale(w,h).ConvertToBitmap())
except:
traceback.print_exc()
wx.MessageBox("无法正常识别,请重新开始.注意数据截取位置.", "提醒", wx.OK)
runflag = 0
示例11: ut_showMouseLoc
def ut_showMouseLoc(self):
points = [(120,120), (600,480), (500,1000), (800,200)]
m = PyMouse() # make mouse object
for point in points:
print "Moving to: ", point
m.move(point[0],point[1])
print "The Mouse is at:", m.position()
print "Test complete!"
示例12: test_move
def test_move(self):
for size in screen_sizes:
with Display(visible=VISIBLE, size=size) as d:
time.sleep(0.5)
mouse = PyMouse(display=d.new_display_var)
for p in positions:
mouse.move(*p)
eq_(expect_pos(p, size), mouse.position())
示例13: test_size
def test_size(self):
for size in screen_sizes:
try:
disp = Display(visible=VISIBLE, size=size).start()
mouse = PyMouse()
eq_(size, mouse.screen_size())
finally:
disp.stop()
示例14: click
def click(p, t = 0.6):
x = p.x
y = p.y
m = PyMouse()
m.move(x, y)
m.click(x, y, 1)
# m.press(x, y)
# m.release(x, y)
time.sleep(t)
示例15: wheel
def wheel(ticks):
"""
Simulates a mouse wheel movement
Args:
ticks (int) : number of increments to scroll the wheel
"""
m = PyMouse()
m.scroll(ticks)