开发者

controlling mouse with pyusb

开发者 https://www.devze.com 2023-04-06 21:38 出处:网络
I have to make a application, that do the followings: disable that the given usb mouse move the pointer in the screen (just the given, not allmouses).

I have to make a application, that do the followings:

  • disable that the given usb mouse move the pointer in the screen (just the given, not all mouses).
  • get the coordinates of the mouse pointer
  • change the y coordinate of the mouse pointer

I've tried out pyusb, but i've never found 开发者_如何转开发any examples for any of the 3 problems.

Any ideas?


I don't know enough pyusb but you can deal with the second issue with Tkinter (one of the most used GUI with Python). Here is a sample of code (found here):

# show mouse position as mouse is moved and create a hot spot

import Tkinter as tk

root = tk.Tk()

def showxy(event):
    xm = event.x
    ym = event.y
    str1 = "mouse at x=%d  y=%d" % (xm, ym)
    root.title(str1)
    # switch color to red if mouse enters a set location range
    x = 100
    y = 100
    delta = 10  # range
    if abs(xm - x) < delta and abs(ym - y) < delta:
        frame.config(bg='red')
    else:
        frame.config(bg='yellow')


frame = tk.Frame(root, bg= 'yellow', width=300, height=200)
frame.bind("<Motion>", showxy)
frame.pack()

root.mainloop()

Yet, it seems like you cannot change the cursor position with Tkinter only (see this thread for some workarounds). But if you are trying to set position within a text, you can use a widget as described in this SO thread: Set cursor position in a Text widget.

To disable mouse, you could have a look at this post and adapt the code to disable mouse instead of touchpad (but the post gives some interesting keys to begin with).

0

精彩评论

暂无评论...
验证码 换一张
取 消