當前位置: 首頁>>代碼示例>>Python>>正文


Python uinput.Device方法代碼示例

本文整理匯總了Python中uinput.Device方法的典型用法代碼示例。如果您正苦於以下問題:Python uinput.Device方法的具體用法?Python uinput.Device怎麽用?Python uinput.Device使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在uinput的用法示例。


在下文中一共展示了uinput.Device方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_altgr_keys

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def get_altgr_keys():
    import sys
    import time
    time.sleep(5)
    device = uinput.Device(uinput_all_keys.uinput_all_keys)
    for i in range(48, 58):
        sys.stdout.write("'")
        sys.stdout.flush()

        for key in wrap_altgr(click(getattr(uinput, "KEY_" + chr(i)))):
            time.sleep(0.1)
            device.emit(*key)
        device.emit_click(uinput.KEY_SPACE)
        time.sleep(0.1)
        sys.stdout.write("': wrap_altgr(click(uinput.KEY_" + chr(i) + ")+click(uinput.KEY_SPACE)),\n")
        sys.stdout.flush() 
開發者ID:JSubelj,項目名稱:g910-gkey-macro-support,代碼行數:18,代碼來源:layout_config_helpers.py

示例2: register_device

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def register_device(keylist):

    return uinput.Device(keylist) 
開發者ID:dillbyrne,項目名稱:es-cec-input,代碼行數:5,代碼來源:es-cec-input.py

示例3: main

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def main():
  #Setup uinput
  events_dpad = (uinput.KEY_UP,uinput.KEY_DOWN,uinput.KEY_LEFT,
                 uinput.KEY_RIGHT,uinput.KEY_ENTER,uinput.KEY_ENTER)
  events_z80 = (uinput.KEY_Q,uinput.KEY_A,uinput.KEY_O,
                uinput.KEY_P,uinput.KEY_M,uinput.KEY_ENTER)
  events=events_z80

  device = uinput.Device(events)
  time.sleep(2) # seconds
  dpad_setup()
  print("DPad Ready!")

  btn_state=[False,False,False,False,False,False]
  key_state=[False,False,False,False,False,False]
  while True:
    #Catch all the buttons pressed before pressing the related keys
    for idx, val in enumerate(BTN):
      if GPIO.input(val) == False:
        btn_state[idx]=True
      else:
        btn_state[idx]=False

    #Perform the button presses/releases
    #(but only change state once)
    for idx, val in enumerate(btn_state):
      if val == True and key_state[idx] == False:
        if DEBUG:print (str(val) + ":" + MSG[idx])
        device.emit(events[idx], 1) # Press.
        key_state[idx]=True
      elif val == False and key_state[idx] == True:
        if DEBUG:print (str(val) + ":!" + MSG[idx])
        device.emit(events[idx], 0) # Release.
        key_state[idx]=False

    time.sleep(.1) 
開發者ID:PacktPublishing,項目名稱:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代碼行數:38,代碼來源:gpiokeys-events.py

示例4: main

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def main():
  #Setup uinput
  events = (uinput.KEY_UP,uinput.KEY_DOWN,uinput.KEY_LEFT,
            uinput.KEY_RIGHT,uinput.KEY_ENTER,uinput.KEY_ENTER)
  device = uinput.Device(events)
  time.sleep(2) # seconds
  dpad_setup()
  print("DPad Ready!")

  btn_state=[False,False,False,False,False,False]
  key_state=[False,False,False,False,False,False]
  while True:
    #Catch all the buttons pressed before pressing the related keys
    for idx, val in enumerate(BTN):
      if GPIO.input(val) == False:
        btn_state[idx]=True
      else:
        btn_state[idx]=False

    #Perform the button presses/releases
    #(but only change state once)
    for idx, val in enumerate(btn_state):
      if val == True and key_state[idx] == False:
        if DEBUG:print (str(val) + ":" + MSG[idx])
        device.emit(events[idx], 1) # Press.
        key_state[idx]=True
      elif val == False and key_state[idx] == True:
        if DEBUG:print (str(val) + ":!" + MSG[idx])
        device.emit(events[idx], 0) # Release.
        key_state[idx]=False

    time.sleep(.1) 
開發者ID:PacktPublishing,項目名稱:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代碼行數:34,代碼來源:gpiokeys.py

示例5: main

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def main():
  #Setup uinput
  events_mouse=(uinput.REL_Y,uinput.REL_Y, uinput.REL_X,
                uinput.REL_X,uinput.BTN_LEFT,uinput.BTN_RIGHT)
  events = events_mouse
  device = uinput.Device(events)
  time.sleep(2) # seconds
  dpad_setup()
  print("DPad Ready!")

  btn_state=[False,False,False,False,False,False]
  key_state=[False,False,False,False,False,False]
  while True:
    #Catch all the buttons pressed before pressing the related keys
    for idx, val in enumerate(BTN):
      if GPIO.input(val) == False:
        btn_state[idx]=True
      else:
        btn_state[idx]=False

    #Perform the button presses/releases
    #(but only change state once)
    for idx, val in enumerate(btn_state):
      if MSG[idx] == "M_UP" or MSG[idx] == "M_LEFT":
        state = -1
      else:
        state = 1
      if val == True:
        device.emit(events[idx], state) # Press.
      elif val == False:
        device.emit(events[idx], 0) # Release.

    time.sleep(0.01) 
開發者ID:PacktPublishing,項目名稱:Raspberry-Pi-3-Cookbook-for-Python-Programmers-Third-Edition,代碼行數:35,代碼來源:gpiokeys-mouse.py

示例6: get_shift_keys

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def get_shift_keys():
    import sys
    import time
    time.sleep(5)
    device = uinput.Device(uinput_all_keys.uinput_all_keys)
    for i in range(48, 58):
        sys.stdout.write("'")
        sys.stdout.flush()

        for key in wrap_shift(click(getattr(uinput, "KEY_" + chr(i)))):
            time.sleep(0.1)
            device.emit(*key)
        sys.stdout.write("': wrap_shift(click(uinput.KEY_" + chr(i) + ")),\n")
        sys.stdout.flush() 
開發者ID:JSubelj,項目名稱:g910-gkey-macro-support,代碼行數:16,代碼來源:layout_config_helpers.py

示例7: test

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def test():
    import sys
    import time

    device = uinput.Device(uinput_all_keys.uinput_all_keys)
    time.sleep(4)
    events = keys['en']
    for key, event in events.items():
        sys.stdout.write("'"+key+"'=='")
        sys.stdout.flush()
        time.sleep(0.1)
        execute_events(event,device)
        time.sleep(0.1)
        sys.stdout.write("'\n") 
開發者ID:JSubelj,項目名稱:g910-gkey-macro-support,代碼行數:16,代碼來源:layout_config_helpers.py

示例8: init_uinput_device

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def init_uinput_device():
    device = uinput.Device(uinput_all_keys.uinput_all_keys)
    log.debug("got uinput device: " + str(device))
    return device 
開發者ID:JSubelj,項目名稱:g910-gkey-macro-support,代碼行數:6,代碼來源:usb_and_keyboard_device_init.py

示例9: read_and_emulate_mouse

# 需要導入模塊: import uinput [as 別名]
# 或者: from uinput import Device [as 別名]
def read_and_emulate_mouse(deviceFound):
    with open(deviceFound, 'rb') as f:
        print("Read buffer")

        device = uinput.Device([
            uinput.BTN_LEFT,
            uinput.BTN_RIGHT,
            uinput.ABS_X,
            uinput.ABS_Y,
        ])
        cal_data = read_pointercal_calib_file()
        
        clicked = False
        rightClicked = False
        (lastX, lastY) = (0, 0)
        startTime = time.time()

        while True:
            try:
                b = f.read(22)
                (tag, btnLeft, x, y) = struct.unpack_from('>c?HH', b)
                print(btnLeft, x, y)
            except:
                print('failed to read from deviceFound' + str(deviceFound))
                syslog.syslog(syslog.LOG_WARNING,'TouchDriver: Failed to read from {0}'.format(deviceFound))
                return
            
            time.sleep(0.01)

            if btnLeft:
                # calc real touch point
                dp = display_touch_point(cal_data, [x,y])
                # dp[0] - LCD X , dp[1] - LCD Y
                device.emit(uinput.ABS_X, dp[0], True)
                device.emit(uinput.ABS_Y, dp[1], True)

                if not clicked:
                    print("Left click")
                    device.emit(uinput.BTN_LEFT, 1)
                    clicked = True
                    startTime = time.time()
                    (lastX, lastY) = (x, y)

                duration = time.time() - startTime
                movement = math.sqrt(pow(x - lastX, 2) + pow(y - lastY, 2))

                if clicked and (not rightClicked) and (duration > 1) and (movement < 20):
                    print("Right click")
                    device.emit(uinput.BTN_RIGHT, 1)
                    device.emit(uinput.BTN_RIGHT, 0)
                    rightClicked = True
            else:
                print("Release")
                clicked = False
                rightClicked = False
                device.emit(uinput.BTN_LEFT, 0) 
開發者ID:saper-2,項目名稱:rpi-5inch-hdmi-touchscreen-driver,代碼行數:58,代碼來源:touch.py


注:本文中的uinput.Device方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。