本文整理汇总了Python中pymouse.PyMouse.press方法的典型用法代码示例。如果您正苦于以下问题:Python PyMouse.press方法的具体用法?Python PyMouse.press怎么用?Python PyMouse.press使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymouse.PyMouse
的用法示例。
在下文中一共展示了PyMouse.press方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
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
示例2: vis
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class Mouse:
@property
def vis(self):
return self._vis
def __init__(self,vis):
self._vis = vis
self.pm = PM()
""" Takes a board coordinate (x,y) and uses self._vis to calculate the
screen coordinates to click there. Then it waits 5.7 ms, and takes a
screenshot"""
def left_click(self,x,y):
#print "clicking at",x,y
x0, y0 = self.vis.edge_coords
x1, y1 = (x0 + 8 + x * 16, y0 + 8 + y * 16)
self.pm.move(x1,y1)
self.pm.click(x1,y1,1)
#time.sleep(0.25)
def right_click(self,x,y):
x0, y0 = self.vis.edge_coords
x1, y1 = (x0 + 8 + x * 16, y0 + 8 + y * 16)
self.pm.click(x1,y1,2)
#time.sleep(0.05)
""" Uses self._vis to determine the position of the smiley reset button"""
def reset_board(self):
(resx, resy) = self.vis.get_reset()
self.pm.move(resx,resy)
self.pm.press(resx,resy,1)
time.sleep(0.5)
self.pm.release(resx,resy,1)
示例3: WinMouseControl
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class WinMouseControl():
mouseObject=''
def __init__(self):
self.mouseObject=PyMouse()
print "mouse init success"
pass
def __del__(self):
pass
def mouseMove(self,x,y,button=None):
self.mouseObject.move(x, y)
return 0
def mouseClick(self,x,y,button):
self.mouseObject.click(x, y, button) #button:1 left, button2: middle button3:right
return 0
def mousePress(self,x,y,button):
self.mouseObject.press(x, y, button) #button:1 left, button2: middle button3:right
return 0
def mouseRelease(self,x,y,button):
self.mouseObject.release(x, y, button) #button:1 left, button2: middle button3:right
return 0
示例4: drag
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def drag(source, dest, speed=1000):
"""
Simulates a smooth mouse drag
Args:
source (int, int) : location (x,y) to start the drag, in screen
coordinates
dest (int, int) : location (x,y) to end the drag, in screen
coordinates
speed (int) : rate at which to execute the drag, in pixels/second
"""
m = PyMouse()
m.press(*source)
time.sleep(0.1)
# number of intermediate movements to make for our given speed
npoints = int(sqrt((dest[0]-source[0])**2 + (dest[1]-source[1])**2 ) / (speed/1000))
for i in range(npoints):
x = int(source[0] + ((dest[0]-source[0])/npoints)*i)
y = int(source[1] + ((dest[1]-source[1])/npoints)*i)
m.move(x,y)
time.sleep(0.001)
m.release(*dest)
示例5: MouseRemote
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class MouseRemote(AweRemPlugin):
"""
Print "RedButton Triggered"
"""
def activate(self):
self.realMouse = PyMouse()
self.handler = MouseHandler(self)
self.info = {"title": "Mouse", "category": "utils",
"priority": 0}
def getHandler(self):
return self.handler
def getInfo(self):
return self.info
def getIconPath(self, dpi):
return ""
def click(self, button, x=None, y=None):
curx, cury = self.realMouse.position()
if x is None:
x = curx
if y is None:
y = cury
self.realMouse.click(x, y, button)
def press(self, button, x=None, y=None):
curx, cury = self.realMouse.position()
if x is None:
x = curx
if y is None:
y = cury
self.realMouse.press(x, y, button)
def release(self, button, x=None, y=None):
curx, cury = self.realMouse.position()
if x is None:
x = curx
if y is None:
y = cury
self.realMouse.release(x, y, button)
def move(self, deltaX, deltaY):
curx, cury = self.realMouse.position()
if deltaX is not None:
curx += deltaX
if deltaY is not None:
cury += deltaY
self.realMouse.move(curx, cury)
def moveAbsolute(self, x, y):
self.realMouse.move(x, y)
示例6: click
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def click(point):
"""
Simulates a mouse click
Args:
point (int,int) : location (x,y) of the screen to click
"""
m = PyMouse()
m.move(*point)
m.press(*point)
m.release(*point)
示例7: press_left
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def press_left(t=1.0) :
m = PyMouse()
xt=random.randint(1400, 1600)
yt=random.randint(260, 500)
m.position()
m.move(xt, yt)
time.sleep(0.2)
m.press(xt, yt)
time.sleep(t)
m.release(xt, yt)
示例8: __init__
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class Player:
def __init__(self):
self.mouse = PyMouse()
def click(self, pos):
self.mouse.click(*pos)
def shoot(self, target, power, table_offset, cue_ball):
adj_target = np.add(target, table_offset)
self.mouse.press(*adj_target)
adj_cue = np.add(cue_ball.get_pos(), table_offset)
self.mouse.drag(*adj_cue)
self.mouse.release(*adj_cue)
示例9: drag
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def drag(p1, p2, t = 0.05):
m = PyMouse()
m.press(p1.x, p1.y, 1)
x = p1.x
y = p1.y
step = 5
while distance(Point(x, y), p2) >= 1 :
x += (p2.x - x)/step
y += (p2.y - y)/step
step -= 1
m.drag(x, y)
# time.sleep(0.01)
m.release(p2.x, p2.y, 1)
time.sleep(t)
示例10: test_event
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def test_event(self):
for size in screen_sizes:
with Display(visible=VISIBLE, size=size):
time.sleep(1.0) # TODO: how long should we wait?
mouse = PyMouse()
event = Event()
event.start()
# check move
for p in positions:
event.reset()
mouse.move(*p)
time.sleep(0.01)
print('check ', expect_pos(p, size), '=', event.pos)
eq_(expect_pos(p, size), event.pos)
# check buttons
for btn in buttons:
# press
event.reset()
mouse.press(0, 0, btn)
time.sleep(0.01)
print("check button", btn, "pressed")
eq_(btn, event.button)
eq_(True, event.press)
# release
event.reset()
mouse.release(0, 0, btn)
time.sleep(0.01)
print("check button", btn, "released")
eq_(btn, event.button)
eq_(False, event.press)
# check scroll
def check_scroll(btn, vertical=None, horizontal=None):
event.reset()
mouse.press(0, 0, btn)
time.sleep(0.01)
if vertical:
eq_(vertical, event.scroll_vertical)
elif horizontal:
eq_(horizontal, event.scroll_horizontal)
print("check scroll up")
check_scroll(4, 1, 0)
print("check scroll down")
check_scroll(5, -1, 0)
print("check scroll left")
check_scroll(6, 0, 1)
print("check scroll right")
check_scroll(7, 0, -1)
event.stop()
示例11: PointerNode
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class PointerNode(Node):
nodeName = "Pointer"
def __init__(self, name):
terminals = {
'irXIn': dict(io='in'),
'irYIn': dict(io='in'),
'bPressed': dict(io='in'),
'aPressed': dict(io='in'),
'bRel': dict(io='in'),
}
self.mouse = PyMouse()
self.screenSize = self.mouse.screen_size()
self.dragging = False
Node.__init__(self, name, terminals=terminals)
def process(self, **kwds):
self.irX = kwds['irXIn']
self.irY = kwds['irYIn']
self.isBPressed = kwds['bPressed']
self.isAPressed = kwds['aPressed']
self.isBReleased = kwds['bRel']
# check if B button is pressed and ir data is not zero
if self.isBPressed and self.irX != 0 and self.irY != 0:
# recalculate the x and y pos of the mouse depending on the ir data and screen size
xScreen = self.screenSize[0] - int((self.screenSize[0] / 1024) * self.irX)
yScreen = int((self.screenSize[1] / 760) * self.irY)
# check if x and y data is valid and move mouse to pos
if xScreen <= self.screenSize[0] and xScreen >= 0 and yScreen <= self.screenSize[1] and yScreen >= 0:
self.mouse.move(xScreen, yScreen)
# when b is released and object is dragged, object is released
if self.isBReleased and self.dragging:
self.mouse.click(self.mouse.position()[0], self.mouse.position()[1])
self.dragging = False
# when b is not pressed and a is pressed, do a single click
if self.isAPressed and not self.isBPressed:
self.mouse.click(self.mouse.position()[0], self.mouse.position()[1])
self.dragging = False
# when b and a are pressed, do drag
elif self.isAPressed and self.isBPressed:
self.mouse.press(self.mouse.position()[0], self.mouse.position()[1])
self.dragging = True
示例12: __init__
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
class HostDeviceClass:
def __init__(self):
self.m = PyMouse()
self.screen = HelperClasses.ScreenClass(self.m.screen_size()[0], self.m.screen_size()[1])
self.cursor = HelperClasses.CursorClass(self.screen.width/2, self.screen.height/2)
def moveCursorToCenter(self):
self.cursor = HelperClasses.CursorClass(self.screen.width/2, self.screen.height/2)
print "Updated Cursor Position to center of screen (" + str(self.cursor.x) + ", " + str(self.cursor.y) + ")."
self.moveCursor()
def moveCursor(self):
self.m.move(self.cursor.x, self.cursor.y)
def mousePress(self):
print "PRESS"
self.m.press(self.cursor.x, self.cursor.y)
def mouseRelease(self):
print "RELEASE"
self.m.release(self.cursor.x, self.cursor.y)
def displaceCursor(self, disp):
# update cursor
new_x = self.cursor.x + disp.x
new_y = self.cursor.y + disp.y
# screen limits
if new_x > self.screen.width:
new_x = self.screen.width
if new_x < 0:
new_x = 0
if new_y > self.screen.height:
new_y = self.screen.height
if new_y < 0:
new_y = 0
actualMovement = HelperClasses.CursorClass(self.cursor.x - new_x, self.cursor.y - new_y)
self.cursor.x = new_x
self.cursor.y = new_y
self.moveCursor()
return actualMovement
示例13: len
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
#always keep maximum of 20 points in the trail
if len(trail)==20:
trail.pop(0)
#append the centroid to the trail
trail.append((cx,cy))
#mouse events by hand pose
if int(resp)==1 and mouse_enable:
if pressed:
pressed=False
m1.release(mx,my)
m1.move(mx,my)
if int(resp)==2 and mouse_enable:
pressed=True
m1.press(mx,my)
#put the hand pose on the display
cv2.putText(img,resp,(x,y), font,1,(255,255,255),2,cv2.LINE_AA)
#draw the trail
for i in xrange(0,len(trail)-1):
cv2.line(img,trail[i],trail[i+1],[0,0,255],2)
#fps calc
fps=int(1/(time.time()-t))
cv2.putText(img,"FPS: "+str(fps),(50,50), font,1,(255,255,255),2,cv2.LINE_AA)
cv2.imshow('Frame',img)
示例14: PyMouse
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
from pymouse import PyMouse
import time
m = PyMouse()
i = 0
while i < 603:
m.click(30,300,1)
time.sleep(1)
m.click(980,515,1)
time.sleep(1)
m.click(1125,715,1)
time.sleep(1)
m.press(638,94,1)
time.sleep(1)
m.release(1395,1055,1)
time.sleep(1)
m.click(1135,675)
time.sleep(1)
m.click(1825,60)
time.sleep(1)
i = i + 1
示例15: rebuy
# 需要导入模块: from pymouse import PyMouse [as 别名]
# 或者: from pymouse.PyMouse import press [as 别名]
def rebuy():
m = PyMouse()
m.press(496,403,1)
wsh.SendKeys("{ENTER} ")