作为以下好答案的替代方案AB:

作为以下好答案的替代方案AB:

我买了一个新键盘,Razer BlackWidow Ultimate Elite. 直到宏键 M1 至 M5 为止,所有键都会操作。

xev此密钥没有输出。有没有办法在 Ubuntu 中使用密钥?

% lsusb | grep Razer
Bus 007 Device 003: ID 1532:011a Razer USA, Ltd

答案1

首先,我们需要一个小的 Python3 脚本,取自这里(请去给@Sergey 点赞;)

我已将产品 ID 替换为我的产品 ID011a

#!/usr/bin/python3

import usb
import sys

VENDOR_ID = 0x1532  # Razer
PRODUCT_ID = 0x011a  # BlackWidow Ultimate Elite

USB_REQUEST_TYPE = 0x21  # Host To Device | Class | Interface
USB_REQUEST = 0x09  # SET_REPORT

USB_VALUE = 0x0300
USB_INDEX = 0x2
USB_INTERFACE = 2

LOG=sys.stderr.write

class blackwidow(object):
  kernel_driver_detached = False

  def __init__(self):
    self.device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)

    if self.device is None:
      raise ValueError("Device {}:{} not found\n".format(VENDOR_ID, PRODUCT_ID))
    else:
      LOG("Found device {}:{}\n".format(VENDOR_ID, PRODUCT_ID))

    if self.device.is_kernel_driver_active(USB_INTERFACE):
      LOG("Kernel driver active. Detaching it.\n")
      self.device.detach_kernel_driver(USB_INTERFACE)
      self.kernel_driver_detached = True

    LOG("Claiming interface\n")
    usb.util.claim_interface(self.device, USB_INTERFACE)

  def __del__(self):
    LOG("Releasing claimed interface\n")
    usb.util.release_interface(self.device, USB_INTERFACE)

    if self.kernel_driver_detached:
      LOG("Reattaching the kernel driver\n")
      self.device.attach_kernel_driver(USB_INTERFACE)

    LOG("Done.\n")

  def bwcmd(self, c):
    from functools import reduce
    c1 = bytes.fromhex(c)
    c2 = [ reduce(int.__xor__, c1) ]
    b = [0] * 90
    b[5:5+len(c1)] = c1
    b[-2:-1] = c2
    return bytes(b)

  def send(self, c):
    def _send(msg):
      USB_BUFFER = self.bwcmd(msg)
      result = 0
      try:
        result = self.device.ctrl_transfer(USB_REQUEST_TYPE, USB_REQUEST, wValue=USB_VALUE, wIndex=USB_INDEX, data_or_wLength=USB_BUFFER)
      except:
        sys.stderr.write("Could not send data.\n")

      if result == len(USB_BUFFER):
        LOG("Data sent successfully.\n")

      return result

    if isinstance(c, list):
#      import time
      for i in c:
        print(' >> {}\n'.format(i))
        _send(i)
#        time.sleep(.05)
    elif isinstance(c, str):
        _send(c)

###############################################################################

def main():
    init_new  = '0200 0403'
    init_old  = '0200 0402'
    pulsate = '0303 0201 0402'
    bright  = '0303 0301 04ff'
    normal  = '0303 0301 04a8'
    dim     = '0303 0301 0454'
    off     = '0303 0301 0400'

    bw = blackwidow()
    bw.send(init_old)

if __name__ == '__main__':
    main()

要启动脚本,我们需要pyusbPython3

sudo pip3 install --upgrade pip
sudo pip3 install pyusb

将 Python 脚本另存为init_blackwidow.py并设置执行权限。现在使用以下命令启动脚本

sudo ./init_blackwidow.py

xev现在您可以使用...检查密钥代码。


… 直到下次重启:\

但我们可以使用/etc/rc.localand udev

  1. 将脚本复制init_blackwidow.py/usr/local/bin

  2. /etc/rc.local在行之前添加以下行exit 0

    /usr/local/bin/init_blackwidow.py
    

    现在你应该有类似这样的东西

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    /usr/local/bin/init_blackwidow.py
    
    exit 0
    
  3. 创建新规则

    SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="1532", ATTR{idProduct}=="011a", RUN+="/usr/local/bin/init_blackwidow.py"
    

    /etc/udev/rules.d/99-razer_blackwidow.rules
    
  4. 重新开始udev

    sudo service udev restart
    

    享受 …

答案2

作为以下好答案的替代方案AB


轻松安装 Razer Chroma 驱动程序

以下项目支持许多 Razer chroma 驱动程序。它还激活 Mx 键。

https://github.com/pez2001/razer_chroma_drivers


MacroW——一个简单的宏播放器/录音机。

有一个用于 M1、M2、M3、M4 和 M5 键的即时宏录制/播放功能,称为宏大. MacroW 使用起来非常简单 (在我看来,作为开发者)。如果您设法激活了 Mx 键并想尝试 MacroW,您可以查看:

https://github.com/igorbb/MacroW

我很想得到一些反馈/帮助。

相关内容