简体   繁体   English

我如何检查鼠标点击 Python 3.8?

[英]How would I check for mouse click on Python 3.8?

How do I check for LMB in Python?如何在 Python 中查看 LMB?

I want to check for when the left mouse button (left click) is clicked to make a drawing system through Kivy. I can't find it anywhere or figure out how to do it.我想检查何时单击鼠标左键(左键单击)以通过 Kivy 制作绘图系统。我无法在任何地方找到它或弄清楚如何去做。

if draw_mode_free == True:
    if playerClicking == True:
        with self.canvas:
   # draw a line using the default color
   Line(points=(x1, y1, x2, y2, x3, y3))

   # lets draw a semi-transparent red square
   Color(0, 0, 0, 1, mode='rgba')
   Rectangle(pos=self.pos, size=self.size)

Use the standard Kivy on_touch_down , on_touch_move and on_touch_up methods to receive and make use of incoming touch events (which includes mouse clicks).使用标准的 Kivy on_touch_downon_touch_moveon_touch_up方法来接收和使用传入的触摸事件(包括鼠标点击)。

The touch objects you receive include data about what button is pressed, accessible via touch.profile['button'] (and possibly directly via touch.button , not sure).您收到的触摸对象包括有关按下哪个按钮的数据,可通过touch.profile['button']访问(也可能直接通过touch.button ,不确定)。

Here is a pice of code which can give the mouse click Try this on your project it may help you这是一段可以让鼠标点击的代码 在你的项目上试试这个可能对你有帮助

from pynput import mouse, keyboard
from pynput.keyboard import Key, Listener
def on_click(x,y, button,pressed):
     if pressed:
         print("mouse click")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM