<i id='cx5Mm'><tr id='cx5Mm'><dt id='cx5Mm'><q id='cx5Mm'><span id='cx5Mm'><b id='cx5Mm'><form id='cx5Mm'><ins id='cx5Mm'></ins><ul id='cx5Mm'></ul><sub id='cx5Mm'></sub></form><legend id='cx5Mm'></legend><bdo id='cx5Mm'><pre id='cx5Mm'><center id='cx5Mm'></center></pre></bdo></b><th id='cx5Mm'></th></span></q></dt></tr></i><div id='cx5Mm'><tfoot id='cx5Mm'></tfoot><dl id='cx5Mm'><fieldset id='cx5Mm'></fieldset></dl></div>

      • <bdo id='cx5Mm'></bdo><ul id='cx5Mm'></ul>

      <legend id='cx5Mm'><style id='cx5Mm'><dir id='cx5Mm'><q id='cx5Mm'></q></dir></style></legend>

    1. <small id='cx5Mm'></small><noframes id='cx5Mm'>

    2. <tfoot id='cx5Mm'></tfoot>

        如何区分pygame中的鼠标左键、右键单击?

        时间:2023-10-09

        <small id='fiI08'></small><noframes id='fiI08'>

            <bdo id='fiI08'></bdo><ul id='fiI08'></ul>

            1. <i id='fiI08'><tr id='fiI08'><dt id='fiI08'><q id='fiI08'><span id='fiI08'><b id='fiI08'><form id='fiI08'><ins id='fiI08'></ins><ul id='fiI08'></ul><sub id='fiI08'></sub></form><legend id='fiI08'></legend><bdo id='fiI08'><pre id='fiI08'><center id='fiI08'></center></pre></bdo></b><th id='fiI08'></th></span></q></dt></tr></i><div id='fiI08'><tfoot id='fiI08'></tfoot><dl id='fiI08'><fieldset id='fiI08'></fieldset></dl></div>
                <tbody id='fiI08'></tbody>
                <tfoot id='fiI08'></tfoot>

                  <legend id='fiI08'><style id='fiI08'><dir id='fiI08'><q id='fiI08'></q></dir></style></legend>
                • 本文介绍了如何区分pygame中的鼠标左键、右键单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  来自pygame的api,它有:

                  From api of pygame, it has:

                  event type.MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION
                  

                  但是没有办法区分左右点击?

                  But there is no way to distinguish between right, left clicks?

                  推荐答案

                  点击事件


                  if event.type == pygame.MOUSEBUTTONDOWN:
                      print(event.button)
                  

                  event.button 可以等于多个整数值:

                  event.button can equal several integer values:

                  1 - left click
                  2 - middle click
                  3 - right click
                  4 - scroll up
                  5 - scroll down
                  

                  获取鼠标状态


                  您也可以获取当前按钮状态,而不是等待事件:

                  Fetching mouse state


                  Instead of waiting for an event, you can get the current button state as well:

                  state = pygame.mouse.get_pressed()
                  

                  这会返回一个元组,格式为:(leftclick, middleclick, rightclick)

                  This returns a tuple in the form: (leftclick, middleclick, rightclick)

                  每个值都是一个布尔整数,表示该按钮是否被按下.

                  Each value is a boolean integer representing whether that button is pressed.

                  这篇关于如何区分pygame中的鼠标左键、右键单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Python 中从同一类中的另一个调用一个方法 下一篇:“之后"无限循环:从不进入主循环

                  相关文章

                  最新文章

                  <i id='AlVpv'><tr id='AlVpv'><dt id='AlVpv'><q id='AlVpv'><span id='AlVpv'><b id='AlVpv'><form id='AlVpv'><ins id='AlVpv'></ins><ul id='AlVpv'></ul><sub id='AlVpv'></sub></form><legend id='AlVpv'></legend><bdo id='AlVpv'><pre id='AlVpv'><center id='AlVpv'></center></pre></bdo></b><th id='AlVpv'></th></span></q></dt></tr></i><div id='AlVpv'><tfoot id='AlVpv'></tfoot><dl id='AlVpv'><fieldset id='AlVpv'></fieldset></dl></div>
                    <bdo id='AlVpv'></bdo><ul id='AlVpv'></ul>
                  1. <legend id='AlVpv'><style id='AlVpv'><dir id='AlVpv'><q id='AlVpv'></q></dir></style></legend>
                  2. <small id='AlVpv'></small><noframes id='AlVpv'>

                      <tfoot id='AlVpv'></tfoot>