久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

        <i id='ccfjj'><tr id='ccfjj'><dt id='ccfjj'><q id='ccfjj'><span id='ccfjj'><b id='ccfjj'><form id='ccfjj'><ins id='ccfjj'></ins><ul id='ccfjj'></ul><sub id='ccfjj'></sub></form><legend id='ccfjj'></legend><bdo id='ccfjj'><pre id='ccfjj'><center id='ccfjj'></center></pre></bdo></b><th id='ccfjj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ccfjj'><tfoot id='ccfjj'></tfoot><dl id='ccfjj'><fieldset id='ccfjj'></fieldset></dl></div>
      1. <legend id='ccfjj'><style id='ccfjj'><dir id='ccfjj'><q id='ccfjj'></q></dir></style></legend>

        <tfoot id='ccfjj'></tfoot>

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

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

        Python鍵盤庫方向鍵問題

        Python keyboard library arrow keys problem(Python鍵盤庫方向鍵問題)

      2. <small id='evVnt'></small><noframes id='evVnt'>

        <legend id='evVnt'><style id='evVnt'><dir id='evVnt'><q id='evVnt'></q></dir></style></legend>
        <i id='evVnt'><tr id='evVnt'><dt id='evVnt'><q id='evVnt'><span id='evVnt'><b id='evVnt'><form id='evVnt'><ins id='evVnt'></ins><ul id='evVnt'></ul><sub id='evVnt'></sub></form><legend id='evVnt'></legend><bdo id='evVnt'><pre id='evVnt'><center id='evVnt'></center></pre></bdo></b><th id='evVnt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='evVnt'><tfoot id='evVnt'></tfoot><dl id='evVnt'><fieldset id='evVnt'></fieldset></dl></div>
      3. <tfoot id='evVnt'></tfoot>

                <tbody id='evVnt'></tbody>
                • <bdo id='evVnt'></bdo><ul id='evVnt'></ul>

                • 本文介紹了Python鍵盤庫方向鍵問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在編寫一個腳本,它會截取屏幕截圖并解碼以圖像名稱命名的特定按鍵,如下所示.我的問題是,當我按下左鍵盤箭頭時,也按下了數字 4.我在谷歌或鍵盤庫的文檔中找不到任何東西.我正在使用 Windows 和 Python 3.6.5

                  I was writing a script, which takes a screenshot and decodes specific key presses in the name of the image as seen below. My problem is that when I press the left keyboard arrow, also the number 4 is pressed. I can't find anything on google or in the documentation of the keyboard library. I am using Windows and Python 3.6.5

                  (75,)
                  left arrow pressed
                  (5, 75)
                  4 pressed
                  

                  向下箭頭也會發生同樣的事情,但數字 3 是這樣的.

                  The same thing happens with the down arrow, but with the number 3.

                  (80,)
                  down arrow pressed
                  (3, 80)
                  2 pressed
                  

                  代碼:

                  from PIL import ImageGrab
                  import keyboard  # using module keyboard
                  import time
                  
                  keys = [
                      "down arrow",
                      "up arrow",
                      "left arrow",
                      "right arrow",
                      "w",
                      "s",
                      "a",
                      "d",
                      "1",
                      "2",
                      "3",
                      "4",
                      "q",
                      
                  

                  e",f"]

                  if __name__ == "__main__":
                      while True:
                          code = []
                          try:
                              for key in keys:
                                  if keyboard.is_pressed(key):
                                      print(keyboard.key_to_scan_codes(key))
                                      print(f"{key} pressed")
                                      code.append(1)
                                  else:
                                      code.append(0)
                                      
                              if keyboard.is_pressed('esc'):
                                  print(key + " pressed")
                                  break
                                  
                              c = "".join(map(str, code))
                              snapshot = ImageGrab.grab()
                              save_path = str(int(time.time()*1000)) + "-" + c + ".jpg"
                              snapshot.save("tmp\" + save_path)
                  
                          except:
                              break
                  

                  推薦答案

                  keyboard 模塊對于此類實例有簡單的解決方案,它們使用 event-triggered 激活而不是polling 在您的嘗試中使用.

                  The keyboard module has simple solutions for instances like these, they use event-triggered activation rather than polling as is used in your attempt.

                  示例代碼:

                  import keyboard
                  
                  def handleLeftKey(e):
                      if keyboard.is_pressed("4"):
                          print("left arrow was pressed w/ key 4")
                          # work your magic
                  
                  keyboard.on_press_key("left", handleLeftKey)
                  # self-explanitory: when the left key is pressed down then do something
                  
                  keyboard.on_release_key("left", handleLeftKey02)
                  # also self-explanitory: when the left key is released then do something
                  
                  # don't use both ...on_release & ...on_press or it will be
                  # triggered twice per key-use (1 up, 1 down)
                  

                  替換下面的代碼并根據您的需要進行更改.

                  Replace the code below and change it to suit your needs.

                  if __name__ == "__main__":
                      while True:
                          code = []
                          try:
                              for key in keys:
                                  if keyboard.is_pressed(key):
                                      print(keyboard.key_to_scan_codes(key))
                                      print(f"{key} pressed")
                                      code.append(1)
                                  else:
                                      code.append(0)
                  

                  另一種更動態的方法如下所示:

                  Another, more dynamic approach would look like:

                  import keyboard
                  
                  keys = [
                      "down",
                      "up",
                      "left",
                      "right",
                      "w",
                      "s",
                      "a",
                      "d",
                      "1",
                      "2",
                      "3",
                      "4",
                      "q",
                      "e",
                      "f"
                  ]
                  
                  def kbdCallback(e):
                      found = False
                      for key in keys:
                          if key == keyboard.normalize_name(e.name):
                              print(f"{key} was pressed")
                              found = True
                              # work your magic
                  
                      if found == True:
                          if e.name == "left":
                              if keyboard.is_pressed("4"):
                                  print("4 & left arrow were pressed together!")
                                  # work your magic
                  
                  keyboard.on_press(kbdCallback)
                  # same as keyboard.on_press_key, but it does this for EVERY key
                  

                  我注意到的另一個問題是您使用 "left arrow" 而實際上它被識別為 "left" (至少在我的系統上,它可能會有所不同在你的,但我假設你希望它在所有系統上工作,所以使用 "left" 會更安全)

                  Another issue I noticed was that you were using "left arrow" when really it was recognized as "left" (at least on my system, it may be different on yours, but I assume you want it to work on all systems so it'd be safer using "left" instead)

                  您可以使用的最后一種方法是非常靜態類型的并且沒有動態功能,但可以在 "4+left""left+4"

                  The last method you could use is very statically typed and has no dynamic capabilities, but would work in the case of "4+left" or "left+4"

                  import keyboard
                  
                  def left4trigger:
                      print("the keys were pressed")
                  
                  keyboard.add_hotkey("4+left", left4trigger)
                  # works as 4+left or left+4 (all of the examples do)
                  

                  你看起來很聰明,可以從那里弄清楚其余的事情.

                  You seem smart enough to figure out the rest from there.

                  這篇關于Python鍵盤庫方向鍵問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                    <legend id='VLibj'><style id='VLibj'><dir id='VLibj'><q id='VLibj'></q></dir></style></legend>
                  • <i id='VLibj'><tr id='VLibj'><dt id='VLibj'><q id='VLibj'><span id='VLibj'><b id='VLibj'><form id='VLibj'><ins id='VLibj'></ins><ul id='VLibj'></ul><sub id='VLibj'></sub></form><legend id='VLibj'></legend><bdo id='VLibj'><pre id='VLibj'><center id='VLibj'></center></pre></bdo></b><th id='VLibj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VLibj'><tfoot id='VLibj'></tfoot><dl id='VLibj'><fieldset id='VLibj'></fieldset></dl></div>
                    <tfoot id='VLibj'></tfoot>

                          <bdo id='VLibj'></bdo><ul id='VLibj'></ul>
                              <tbody id='VLibj'></tbody>

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

                            主站蜘蛛池模板: 国产激情在线 | 国产精品成人国产乱一区 | 亚洲成人一级片 | 91视频大全 | 国产精品久久久久久久一区二区 | 免费视频一区二区 | 国产高清久久久 | 欧美成人在线免费 | 国产精品一区二区久久 | 亚洲一区二区三区在线 | 国产欧美日韩精品在线观看 | 亚洲精品 在线播放 | av在线电影网站 | 中文无吗 | 久久免费国产视频 | 久久综合av | 欧美偷偷操 | 日韩欧美国产一区二区 | 中文字幕亚洲视频 | 国产成人99av超碰超爽 | 国产麻豆乱码精品一区二区三区 | 国产精品久久久久久一区二区三区 | 成人欧美一区二区三区在线观看 | 91精品国产91久久综合桃花 | 欧美日韩一区二区三区四区 | 91最新在线视频 | 伦理二区| 日韩欧美亚洲 | 欧美一级做a爰片免费视频 国产美女特级嫩嫩嫩bbb片 | 高清色| 中文字幕视频在线观看 | 欧美日韩中文字幕在线 | 波多野结衣精品在线 | 国产精品亚洲综合 | 中文字幕99 | 久久人人爽人人爽人人片av免费 | 午夜久久av | av毛片 | 亚洲精品日韩欧美 | 91色综合| 不卡av电影在线播放 |