精华内容
下载资源
问答
  • 主要介绍了Python wxpython模块响应鼠标拖动事件操作,结合实例形式分析了Python使用wxpython模块创建窗口、绑定事件及相应鼠标事件相关操作技巧,需要的朋友可以参考下
  • 主要介绍了python模拟鼠标拖动操作的方法,实例分析了Python鼠标操作及键位操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
  • 作者:w_p_ 字体:[增加 减小] 类型:转载这篇文章主要介绍了python模拟鼠标拖动操作的方法,实例分析了Python鼠标操作及键位操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下本文实例讲述了python模拟鼠标拖动...

    作者:w_p_ 字体:[增加 减小] 类型:转载

    这篇文章主要介绍了python模拟鼠标拖动操作的方法,实例分析了Python鼠标操作及键位操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

    本文实例讲述了python模拟鼠标拖动操作的方法,

    pdf中的书签只有页码,准备把现有书签拖到一个目录中,然后添加自己页签。重复的拖动工作实在无趣,还是让程序帮我实现吧,我可以喝点水,休息一下了

    1. Python代码

    代码如下:

    #

    # _*_ coding:UTF-8 _*_

    __author__ = ‘wp‘

    import win32api

    import win32con

    import win32gui

    from ctypes import *

    import time

    SW = 1377

    SH = 768

    VK_CODE = {

    ‘backspace‘:0x08,

    ‘tab‘:0x09,

    ‘clear‘:0x0C,

    ‘enter‘:0x0D,

    ‘shift‘:0x10,

    ‘ctrl‘:0x11,

    ‘alt‘:0x12,

    ‘pause‘:0x13,

    ‘caps_lock‘:0x14,

    ‘esc‘:0x1B,

    ‘spacebar‘:0x20,

    ‘page_up‘:0x21,

    ‘page_down‘:0x22,

    ‘end‘:0x23,

    ‘home‘:0x24,

    ‘left_arrow‘:0x25,

    ‘up_arrow‘:0x26,

    ‘right_arrow‘:0x27,

    ‘down_arrow‘:0x28,

    ‘select‘:0x29,

    ‘print‘:0x2A,

    ‘execute‘:0x2B,

    ‘print_screen‘:0x2C,

    ‘ins‘:0x2D,

    ‘del‘:0x2E,

    ‘help‘:0x2F,

    ‘0‘:0x30,

    ‘1‘:0x31,

    ‘2‘:0x32,

    ‘3‘:0x33,

    ‘4‘:0x34,

    ‘5‘:0x35,

    ‘6‘:0x36,

    ‘7‘:0x37,

    ‘8‘:0x38,

    ‘9‘:0x39,

    ‘a‘:0x41,

    ‘b‘:0x42,

    ‘c‘:0x43,

    ‘d‘:0x44,

    ‘e‘:0x45,

    ‘f‘:0x46,

    ‘g‘:0x47,

    ‘h‘:0x48,

    ‘i‘:0x49,

    ‘j‘:0x4A,

    ‘k‘:0x4B,

    ‘l‘:0x4C,

    ‘m‘:0x4D,

    ‘n‘:0x4E,

    ‘o‘:0x4F,

    ‘p‘:0x50,

    ‘q‘:0x51,

    ‘r‘:0x52,

    ‘s‘:0x53,

    ‘t‘:0x54,

    ‘u‘:0x55,

    ‘v‘:0x56,

    ‘w‘:0x57,

    ‘x‘:0x58,

    ‘y‘:0x59,

    ‘z‘:0x5A,

    ‘numpad_0‘:0x60,

    ‘numpad_1‘:0x61,

    ‘numpad_2‘:0x62,

    ‘numpad_3‘:0x63,

    ‘numpad_4‘:0x64,

    ‘numpad_5‘:0x65,

    ‘numpad_6‘:0x66,

    ‘numpad_7‘:0x67,

    ‘numpad_8‘:0x68,

    ‘numpad_9‘:0x69,

    ‘multiply_key‘:0x6A,

    ‘add_key‘:0x6B,

    ‘separator_key‘:0x6C,

    ‘subtract_key‘:0x6D,

    ‘decimal_key‘:0x6E,

    ‘divide_key‘:0x6F,

    ‘F1‘:0x70,

    ‘F2‘:0x71,

    ‘F3‘:0x72,

    ‘F4‘:0x73,

    ‘F5‘:0x74,

    ‘F6‘:0x75,

    ‘F7‘:0x76,

    ‘F8‘:0x77,

    ‘F9‘:0x78,

    ‘F10‘:0x79,

    ‘F11‘:0x7A,

    ‘F12‘:0x7B,

    ‘F13‘:0x7C,

    ‘F14‘:0x7D,

    ‘F15‘:0x7E,

    ‘F16‘:0x7F,

    ‘F17‘:0x80,

    ‘F18‘:0x81,

    ‘F19‘:0x82,

    ‘F20‘:0x83,

    ‘F21‘:0x84,

    ‘F22‘:0x85,

    ‘F23‘:0x86,

    ‘F24‘:0x87,

    ‘num_lock‘:0x90,

    ‘scroll_lock‘:0x91,

    ‘left_shift‘:0xA0,

    ‘right_shift ‘:0xA1,

    ‘left_control‘:0xA2,

    ‘right_control‘:0xA3,

    ‘left_menu‘:0xA4,

    ‘right_menu‘:0xA5,

    ‘browser_back‘:0xA6,

    ‘browser_forward‘:0xA7,

    ‘browser_refresh‘:0xA8,

    ‘browser_stop‘:0xA9,

    ‘browser_search‘:0xAA,

    ‘browser_favorites‘:0xAB,

    ‘browser_start_and_home‘:0xAC,

    ‘volume_mute‘:0xAD,

    ‘volume_Down‘:0xAE,

    ‘volume_up‘:0xAF,

    ‘next_track‘:0xB0,

    ‘previous_track‘:0xB1,

    ‘stop_media‘:0xB2,

    ‘play/pause_media‘:0xB3,

    ‘start_mail‘:0xB4,

    ‘select_media‘:0xB5,

    ‘start_application_1‘:0xB6,

    ‘start_application_2‘:0xB7,

    ‘attn_key‘:0xF6,

    ‘crsel_key‘:0xF7,

    ‘exsel_key‘:0xF8,

    ‘play_key‘:0xFA,

    ‘zoom_key‘:0xFB,

    ‘clear_key‘:0xFE,

    ‘+‘:0xBB,

    ‘,‘:0xBC,

    ‘-‘:0xBD,

    ‘.‘:0xBE,

    ‘/‘:0xBF,

    ‘`‘:0xC0,

    ‘;‘:0xBA,

    ‘[‘:0xDB,

    ‘\\‘:0xDC,

    ‘]‘:0xDD,

    "‘":0xDE,

    ‘`‘:0xC0}

    class POINT(Structure):

    _fields_ = [("x", c_ulong),("y", c_ulong)]

    def get_mouse_point():

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    return int(po.x), int(po.y)

    def mouse_click(x=None,y=None):

    if not x is None and not y is None:

    mouse_move(x,y)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def mouse_dclick(x=None,y=None):

    if not x is None and not y is None:

    mouse_move(x,y)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def mouse_move(x,y):

    windll.user32.SetCursorPos(x, y)

    def mouse_absolute(x,y,x2,y2):

    windll.user32.SetCursorPos(x, y)   #鼠标移动到

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)   #左键按下

    time.sleep(0.2)

    mw = int(x2 * 65535 / SW)

    mh = int(y2 * 65535 / SH)

    win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE, mw, mh, 0, 0)

    time.sleep(0.2)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def key_input(str=‘‘):

    for c in str:

    win32api.keybd_event(VK_CODE[c],0,0,0)

    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)

    time.sleep(0.01)

    def t0():

    pass #do nothing

    def t2():

    mouse_click(800,200)

    for c in ‘hello‘:

    win32api.keybd_event(65,0,0,0) #a键位码是86

    win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0)

    #print get_mouse_point()

    def t1():

    #mouse_move(1024,470)aa

    #time.sleep(0.05)

    #mouse_dclick()HELLO

    mouse_dclick(1024,470)

    def t3():

    mouse_click(1024,470)

    str = ‘hello‘

    for c in str:

    win32api.keybd_event(VK_CODE[c],0,0,0) #a键位码是86

    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)

    time.sleep(0.01)

    def t4():

    mouse_click(900,300)

    str = ‘hello‘

    key_input(str)

    def t5():

    #拖动pdf中的书签

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    j = 50      #操作次数

    x = 766    #x

    y = 500    #y

    n = 10      #上移10

    for i in range(0,j):

    mouse_absolute(x,y,x,y-n)

    #windll.user32.SetCursorPos(po.x, po.y)

    mouse_click(po.x, po.y)

    print(str(j-i))

    if __name__ == "__main__":

    t5()   #move pdf bookmark

    #t4()

    #t3()

    #t2()

    #t1()

    #t0()

    2. mouse.py文件

    代码如下:

    #

    # _*_ coding:UTF-8 _*_

    __author__ = ‘wp‘

    import win32api

    import win32con

    import win32gui

    from ctypes import *

    import time

    SW = 1377

    SH = 768

    VK_CODE = {

    ‘backspace‘:0x08,

    ‘tab‘:0x09,

    ‘clear‘:0x0C,

    ‘enter‘:0x0D,

    ‘shift‘:0x10,

    ‘ctrl‘:0x11,

    ‘alt‘:0x12,

    ‘pause‘:0x13,

    ‘caps_lock‘:0x14,

    ‘esc‘:0x1B,

    ‘spacebar‘:0x20,

    ‘page_up‘:0x21,

    ‘page_down‘:0x22,

    ‘end‘:0x23,

    ‘home‘:0x24,

    ‘left_arrow‘:0x25,

    ‘up_arrow‘:0x26,

    ‘right_arrow‘:0x27,

    ‘down_arrow‘:0x28,

    ‘select‘:0x29,

    ‘print‘:0x2A,

    ‘execute‘:0x2B,

    ‘print_screen‘:0x2C,

    ‘ins‘:0x2D,

    ‘del‘:0x2E,

    ‘help‘:0x2F,

    ‘0‘:0x30,

    ‘1‘:0x31,

    ‘2‘:0x32,

    ‘3‘:0x33,

    ‘4‘:0x34,

    ‘5‘:0x35,

    ‘6‘:0x36,

    ‘7‘:0x37,

    ‘8‘:0x38,

    ‘9‘:0x39,

    ‘a‘:0x41,

    ‘b‘:0x42,

    ‘c‘:0x43,

    ‘d‘:0x44,

    ‘e‘:0x45,

    ‘f‘:0x46,

    ‘g‘:0x47,

    ‘h‘:0x48,

    ‘i‘:0x49,

    ‘j‘:0x4A,

    ‘k‘:0x4B,

    ‘l‘:0x4C,

    ‘m‘:0x4D,

    ‘n‘:0x4E,

    ‘o‘:0x4F,

    ‘p‘:0x50,

    ‘q‘:0x51,

    ‘r‘:0x52,

    ‘s‘:0x53,

    ‘t‘:0x54,

    ‘u‘:0x55,

    ‘v‘:0x56,

    ‘w‘:0x57,

    ‘x‘:0x58,

    ‘y‘:0x59,

    ‘z‘:0x5A,

    ‘numpad_0‘:0x60,

    ‘numpad_1‘:0x61,

    ‘numpad_2‘:0x62,

    ‘numpad_3‘:0x63,

    ‘numpad_4‘:0x64,

    ‘numpad_5‘:0x65,

    ‘numpad_6‘:0x66,

    ‘numpad_7‘:0x67,

    ‘numpad_8‘:0x68,

    ‘numpad_9‘:0x69,

    ‘multiply_key‘:0x6A,

    ‘add_key‘:0x6B,

    ‘separator_key‘:0x6C,

    ‘subtract_key‘:0x6D,

    ‘decimal_key‘:0x6E,

    ‘divide_key‘:0x6F,

    ‘F1‘:0x70,

    ‘F2‘:0x71,

    ‘F3‘:0x72,

    ‘F4‘:0x73,

    ‘F5‘:0x74,

    ‘F6‘:0x75,

    ‘F7‘:0x76,

    ‘F8‘:0x77,

    ‘F9‘:0x78,

    ‘F10‘:0x79,

    ‘F11‘:0x7A,

    ‘F12‘:0x7B,

    ‘F13‘:0x7C,

    ‘F14‘:0x7D,

    ‘F15‘:0x7E,

    ‘F16‘:0x7F,

    ‘F17‘:0x80,

    ‘F18‘:0x81,

    ‘F19‘:0x82,

    ‘F20‘:0x83,

    ‘F21‘:0x84,

    ‘F22‘:0x85,

    ‘F23‘:0x86,

    ‘F24‘:0x87,

    ‘num_lock‘:0x90,

    ‘scroll_lock‘:0x91,

    ‘left_shift‘:0xA0,

    ‘right_shift ‘:0xA1,

    ‘left_control‘:0xA2,

    ‘right_control‘:0xA3,

    ‘left_menu‘:0xA4,

    ‘right_menu‘:0xA5,

    ‘browser_back‘:0xA6,

    ‘browser_forward‘:0xA7,

    ‘browser_refresh‘:0xA8,

    ‘browser_stop‘:0xA9,

    ‘browser_search‘:0xAA,

    ‘browser_favorites‘:0xAB,

    ‘browser_start_and_home‘:0xAC,

    ‘volume_mute‘:0xAD,

    ‘volume_Down‘:0xAE,

    ‘volume_up‘:0xAF,

    ‘next_track‘:0xB0,

    ‘previous_track‘:0xB1,

    ‘stop_media‘:0xB2,

    ‘play/pause_media‘:0xB3,

    ‘start_mail‘:0xB4,

    ‘select_media‘:0xB5,

    ‘start_application_1‘:0xB6,

    ‘start_application_2‘:0xB7,

    ‘attn_key‘:0xF6,

    ‘crsel_key‘:0xF7,

    ‘exsel_key‘:0xF8,

    ‘play_key‘:0xFA,

    ‘zoom_key‘:0xFB,

    ‘clear_key‘:0xFE,

    ‘+‘:0xBB,

    ‘,‘:0xBC,

    ‘-‘:0xBD,

    ‘.‘:0xBE,

    ‘/‘:0xBF,

    ‘`‘:0xC0,

    ‘;‘:0xBA,

    ‘[‘:0xDB,

    ‘\\‘:0xDC,

    ‘]‘:0xDD,

    "‘":0xDE,

    ‘`‘:0xC0}

    class POINT(Structure):

    _fields_ = [("x", c_ulong),("y", c_ulong)]

    def get_mouse_point():

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    return int(po.x), int(po.y)

    def mouse_click(x=None,y=None):

    if not x is None and not y is None:

    mouse_move(x,y)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def mouse_dclick(x=None,y=None):

    if not x is None and not y is None:

    mouse_move(x,y)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def mouse_move(x,y):

    windll.user32.SetCursorPos(x, y)

    def mouse_absolute(x,y,x2,y2):

    windll.user32.SetCursorPos(x, y)   #鼠标移动到

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)   #左键按下

    time.sleep(0.2)

    mw = int(x2 * 65535 / SW)

    mh = int(y2 * 65535 / SH)

    win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE, mw, mh, 0, 0)

    time.sleep(0.2)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

    def key_input(str=‘‘):

    for c in str:

    win32api.keybd_event(VK_CODE[c],0,0,0)

    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)

    time.sleep(0.01)

    def t0():

    pass #do nothing

    def t2():

    mouse_click(800,200)

    for c in ‘hello‘:

    win32api.keybd_event(65,0,0,0) #a键位码是86

    win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0)

    #print get_mouse_point()

    def t1():

    #mouse_move(1024,470)aa

    #time.sleep(0.05)

    #mouse_dclick()HELLO

    mouse_dclick(1024,470)

    def t3():

    mouse_click(1024,470)

    str = ‘hello‘

    for c in str:

    win32api.keybd_event(VK_CODE[c],0,0,0) #a键位码是86

    win32api.keybd_event(VK_CODE[c],0,win32con.KEYEVENTF_KEYUP,0)

    time.sleep(0.01)

    def t4():

    mouse_click(900,300)

    str = ‘hello‘

    key_input(str)

    def t5():

    #拖动pdf中的书签

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    j = 50      #操作次数

    x = 766    #x

    y = 500    #y

    n = 10      #上移10

    for i in range(0,j):

    mouse_absolute(x,y,x,y-n)

    #windll.user32.SetCursorPos(po.x, po.y)

    mouse_click(po.x, po.y)

    print(str(j-i))

    if __name__ == "__main__":

    t5()   #move pdf bookmark

    #t4()

    #t3()

    #t2()

    #t1()

    #t0()

    3. 运行效果如下:

    希望本文所述对大家的Python程序设计有所帮助,python模拟鼠标拖动操作的方法》(https://www.unjs.com)。

    展开全文
  • python模拟鼠标拖动教程#!/usr/bin/python#-*- coding: UTF-8 -*-frompymouse import PyMousem=PyMouse()m.press(125,359)m.release(472,215)那真的是很简单了press release 都在自带move方法了接下来要说的是 怎么...

    python模拟鼠标拖动教程

    #!/usr/bin/python

    #-*- coding: UTF-8 -*-

    frompymouse import PyMouse

    m=PyMouse()

    m.press(125,359)

    m.release(472,215)

    那真的是很简单了

    press release 都在自带move方法了

    接下来要说的是 怎么模拟真实环境的鼠标拖动  pymouse都是舜闪。。。没有过程

    先装插件

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  pyautogui

    插件文档地址 https://pypi.org/project/PyAutoGUI/0.9.5/

    #!/usr/bin/python

    # -*- coding: UTF-8 -*-

    import time

    import pyautogui

    # while 1:

    # time.sleep(30);

    pyautogui.moveTo(216, 316, 0.5)

    pyautogui.dragRel(0, -160, 0.5)

    移动到411,362 然后往上 拖动-160 拖动用了相对坐标

    ps:注意 用死循环遍历 的时候 用python运行 不要直接编译 不然都停不掉

    以上就是python模拟鼠标拖动教程的全部内容。

    展开全文
  • y) #鼠标移动到 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0) #左键按下 time.sleep(0.2) mw = int(x2 * 65535 / SW) mh = int(y2 * 65535 / SH) win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + ...

    下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

    编程之家小编现在分享给大家,也给大家做个参考。

    #

    # _*_ coding:UTF-8 _*_

    __author__ = 'wp'

    import win32api

    import win32con

    import win32gui

    from ctypes import *

    import time

    SW = 1377

    SH = 768

    VK_CODE = {

    'backspace':0x08,'tab':0x09,'clear':0x0C,'enter':0x0D,'shift':0x10,'ctrl':0x11,'alt':0x12,'pause':0x13,'caps_lock':0x14,'esc':0x1B,'spacebar':0x20,'page_up':0x21,'page_down':0x22,'end':0x23,'home':0x24,'left_arrow':0x25,'up_arrow':0x26,'right_arrow':0x27,'down_arrow':0x28,'select':0x29,'print':0x2A,'execute':0x2B,'print_screen':0x2C,'ins':0x2D,'del':0x2E,'help':0x2F,'0':0x30,'1':0x31,'2':0x32,'3':0x33,'4':0x34,'5':0x35,'6':0x36,'7':0x37,'8':0x38,'9':0x39,'a':0x41,'b':0x42,'c':0x43,'d':0x44,'e':0x45,'f':0x46,'g':0x47,'h':0x48,'i':0x49,'j':0x4A,'k':0x4B,'l':0x4C,'m':0x4D,'n':0x4E,'o':0x4F,'p':0x50,'q':0x51,'r':0x52,'s':0x53,'t':0x54,'u':0x55,'v':0x56,'w':0x57,'x':0x58,'y':0x59,'z':0x5A,'numpad_0':0x60,'numpad_1':0x61,'numpad_2':0x62,'numpad_3':0x63,'numpad_4':0x64,'numpad_5':0x65,'numpad_6':0x66,'numpad_7':0x67,'numpad_8':0x68,'numpad_9':0x69,'multiply_key':0x6A,'add_key':0x6B,'separator_key':0x6C,'subtract_key':0x6D,'decimal_key':0x6E,'divide_key':0x6F,'F1':0x70,'F2':0x71,'F3':0x72,'F4':0x73,'F5':0x74,'F6':0x75,'F7':0x76,'F8':0x77,'F9':0x78,'F10':0x79,'F11':0x7A,'F12':0x7B,'F13':0x7C,'F14':0x7D,'F15':0x7E,'F16':0x7F,'F17':0x80,'F18':0x81,'F19':0x82,'F20':0x83,'F21':0x84,'F22':0x85,'F23':0x86,'F24':0x87,'num_lock':0x90,'scroll_lock':0x91,'left_shift':0xA0,'right_shift ':0xA1,'left_control':0xA2,'right_control':0xA3,'left_menu':0xA4,'right_menu':0xA5,'browser_back':0xA6,'browser_forward':0xA7,'browser_refresh':0xA8,'browser_stop':0xA9,'browser_search':0xAA,'browser_favorites':0xAB,'browser_start_and_home':0xAC,'volume_mute':0xAD,'volume_Down':0xAE,'volume_up':0xAF,'next_track':0xB0,'previous_track':0xB1,'stop_media':0xB2,'play/pause_media':0xB3,'start_mail':0xB4,'select_media':0xB5,'start_application_1':0xB6,'start_application_2':0xB7,'attn_key':0xF6,'crsel_key':0xF7,'exsel_key':0xF8,'play_key':0xFA,'zoom_key':0xFB,'clear_key':0xFE,'+':0xBB,',':0xBC,'-':0xBD,'.':0xBE,'/':0xBF,'`':0xC0,';':0xBA,'[':0xDB,'\\':0xDC,']':0xDD,"'":0xDE,'`':0xC0}

    class POINT(Structure):

    _fields_ = [("x",c_ulong),("y",c_ulong)]

    def get_mouse_point():

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    return int(po.x),int(po.y)

    def mouse_click(x=None,y=None):

    if not x is None and not y is None:

    mouse_move(x,y)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0)

    def mouse_dclick(x=None,0)

    time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0)

    def mouse_move(x,y):

    windll.user32.SetCursorPos(x,y)

    def mouse_absolute(x,y,x2,y2):

    windll.user32.SetCursorPos(x,y) #鼠标移动到

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0) #左键按下

    time.sleep(0.2)

    mw = int(x2 * 65535 / SW)

    mh = int(y2 * 65535 / SH)

    win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE,mw,mh,0)

    time.sleep(0.2)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0)

    def key_input(str=''):

    for c in str:

    win32api.keybd_event(VK_CODE[c],0)

    win32api.keybd_event(VK_CODE[c],win32con.KEYEVENTF_KEYUP,0)

    time.sleep(0.01)

    def t0():

    pass #do nothing

    def t2():

    mouse_click(800,200)

    for c in 'hello':

    win32api.keybd_event(65,0) #a键位码是86

    win32api.keybd_event(65,0)

    #print get_mouse_point()

    def t1():

    #mouse_move(1024,470)aa

    #time.sleep(0.05)

    #mouse_dclick()HELLO

    mouse_dclick(1024,470)

    def t3():

    mouse_click(1024,470)

    str = 'hello'

    for c in str:

    win32api.keybd_event(VK_CODE[c],0) #a键位码是86

    win32api.keybd_event(VK_CODE[c],0)

    time.sleep(0.01)

    def t4():

    mouse_click(900,300)

    str = 'hello'

    key_input(str)

    def t5():

    #拖动pdf中的书签

    po = POINT()

    windll.user32.GetCursorPos(byref(po))

    j = 50 #操作次数

    x = 766 #x

    y = 500 #y

    n = 10 #上移10

    for i in range(0,j):

    mouse_absolute(x,x,y-n)

    #windll.user32.SetCursorPos(po.x,po.y)

    mouse_click(po.x,po.y)

    print(str(j-i))

    if __name__ == "__main__":

    t5() #move pdf bookmark

    #t4()

    #t3()

    #t2()

    #t1()

    #t0()

    以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

    如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

    展开全文
  • 用matplotlib制作一个鼠标拖动点移动改变曲线形状的效果 一、效果预览 二、代码 最近时间精力有限,不能程序每一步都写的很详细,以下是全部代码,带有一定的注释: import numpy as np import pandas as pd import...

    前言

    用matplotlib制作一个鼠标拖动点移动改变曲线形状的效果

    一、效果预览

    在这里插入图片描述

    二、代码

    最近时间精力有限,不能程序每一步都写的很详细,以下是全部代码,带有一定的注释:

    import matplotlib.pyplot as plt#导入画图的包matplotlib
    import numpy as np
    from scipy.optimize import curve_fit#导入拟合曲线方程的包
    
    #先生成一群点,把点画出来
    fig, ax = plt.subplots()
    x = np.array([-5,-4,-3,-2,-1,0, 1,2,3,4,5]).astype(np.float64)#点的横坐标,放在一个数组里面
    y = np.square(x).astype(np.float64)#y=x^2,根据x生成y的坐标,我这里用的二次曲线方程
    plt.ylim(-5, 35)#坐标系y轴范围
    ax.scatter(x,y)#画成散点图
    
    # 忽略除以0的报错
    np.seterr(divide='ignore', invalid='ignore')
    
    # 二阶曲线方程
    def func_2(x, a, b, c):
        return a * np.power(x, 2) + b * x + c
    
    # 鼠标点击事件  函数里面又绑定了一个鼠标移动事件,所以生成的效果是鼠标按下并且移动的时候
    def on_button_press(event):
        fig.canvas.mpl_connect('motion_notify_event', on_button_move)
    
    #on_button_move 鼠标移动事件
    def on_button_move(event,y=y):
        if event.button==2:#123分别代表鼠标的左键、中键、右键,我这里用的是鼠标中键,根据自己的喜好选择吧
            x_mouse, y_mouse= event.xdata, event.ydata#拿到鼠标当前的横纵坐标
    
            ind=[]#这里生成一个列表存储一下要移动的那个点
            #计算一下鼠标的位置和图上点的位置距离,如果距离很近就移动图上那个点
            for i in range(len(x)):
                #计算一下距离 图上每个点都和鼠标计算一下距离
                d = np.sqrt((x_mouse -x[i] ) ** 2 + (y_mouse -y[i]) ** 2)
                if d<0.8:#这里设置一个阈值,如果距离很近,就把它添加到那个列表中去
                    ind.append(i)
    
            if ind:#如果ind里面有元素,说明当前鼠标的位置距离图上的一个点很近    
                #通过索引ind[0]去改变当前这个点的坐标,新坐标是当前鼠标的横纵坐标(这样给人的感觉就是这个点跟着鼠标动了)    
                y[ind[0]] = y_mouse
                x[ind[0]] = x_mouse
                
                #然后根据所有点拟合出来一个二次方程曲线
                popt2, pcov2 = curve_fit(func_2, x, y)
                a2 = popt2[0]
                b2 = popt2[1]
                c2 = popt2[2]
                yvals2 = func_2(x, a2, b2, c2)
                
                #拟合好了以后把曲线画出来
                ax.cla()
                plt.ylim(-5, 35)
                ax.scatter(x, y)
                ax.plot(x, yvals2)
                fig.canvas.draw_idle()  # 重新绘制整个图表,所以看到的就是鼠标移动点然后曲线也跟着在变动
    
    #鼠标释放事件,鼠标松开的时候,就把上面鼠标点击并且移动的关系解绑  这样鼠标松开的时候 就不会拖动点了
    def on_button_release(event):
        fig.canvas.mpl_disconnect( fig.canvas.mpl_connect('motion_notify_event', on_button_move))  # 鼠标释放事件
    
    fig.canvas.mpl_disconnect(fig.canvas.manager.key_press_handler_id)  # 取消默认快捷键的注册,
    fig.canvas.mpl_connect('button_press_event', on_button_press)#鼠标点击事件 
    fig.canvas.mpl_connect('button_release_event', on_button_release)#鼠标松开
    plt.show()#显示图像
    

    三、增加了鼠标滚轮可以放大缩小的功能

    最近时间精力有限,在上面的基础上增加了鼠标滚轮放大缩小功能,点击本链接可以看得到

    总结

    如果您发现我写的有错误,欢迎在评论区批评指正!
    CV

    展开全文
  • import tkinterwin = tkinter.Tk()win.title("鼠标拖动事件")win.geometry("800x600+600+100")#<B1-Motion> 拖动左键触发事件#<B2-Motion> 拖动中键触发事件#<B3-Motion> 拖动右键触发事件label=...
  • 提供了任意窗口位置鼠标拖动窗口的支持 from tkinter import Tk class PfTk(Tk): """ Tk的扩展 增加了对鼠标左键拖动的支持 封装了部分功能方法 """ def __init__(self, title='PfTk', width=300, height...
  • 场景前景讲解了鼠标的click()事件,而我们在实际的web产品测试中,有关鼠标的操作,不仅仅只有单击,有时候还包括右击,双击,拖动等操作,这些操作包含在ActionChains类中。ActionChains类鼠标操作的常用方法:...
  • python : 3.7.0OS : Ubuntu 18.04.1 LTSIDE : PyCharm 2018.2.4conda : 4.5.11type setting : Markdown?code"""@Author : 行初心@Date : 18-9-30@Blog : ...
  • Python之pygame的鼠标事件

    千次阅读 2020-12-05 12:02:10
    鼠标当显示模式设置后,事件队列就会开始收到鼠标事件。当按下和释放鼠标的按键时,会产生pygame.MOUSEBUTTONDOWN和pygame.MOUSEBUTTONUP事件。这些事件包含一个button属性表示哪些键被按下。滚动鼠标滚轮会产生...
  • tkinter小部件拖动效果 刚接触不久,想做一个类似纸牌空挡接龙的游戏,需要一个拖动的效果,找遍全网都没找到.自己动手做了一个.下面写一个教程,不仅仅是代码,也包括思路,用到的函数和方法的解释, 以及我的一些学习...
  • Python(三)鼠标事件

    千次阅读 2020-09-11 19:21:46
    一、鼠标事件 ActionChains类包含了鼠标操作。 ActionChains类中鼠标操作的常用方法: context_click()------------------右击 double_click()-------------------双击 drag_and_drop()---------------拖动 move_to_...
  • 一款跨平台/无依赖的自动化测试工具,目测只能控制鼠标/键盘/获取屏幕尺寸/弹出消息框/截屏。 安装 pip install pyautogui 鼠标键盘控制 >>> import pyautogui >>> screenWidth, screenHeight = pyautogui.size()...
  • 本文实例讲述了Python中pygame的mouse鼠标事件用法。分享给大家供大家参考,具体如下:pygame.mouse提供了一些方法获取鼠标设备当前的状态‘‘‘pygame.mouse.get_pressed - get the state of the mouse buttons get...
  • 一、前言除了可以使用 click( ) 来模拟鼠标的单击操作,现在Web产品中还提供了更丰富的鼠标交互方式,例如鼠标右键、双击、悬停、拖动等功能,在WebDriver中,将这些关于鼠标操作的方法都封装在 ActionChains 类中。...
  • # -*- coding: utf-8 -*-#鼠标事件#ActionChains类中包括:# context_click() 右击;# double_click() 双击;# drag_and_drop() 拖动;# move_to_element()鼠标悬停在一个元素上;#首先引入ActionChainsfrom ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 9,593
精华内容 3,837
关键字:

python鼠标拖动事件

python 订阅