謎のキー入れ替え設定メモ

(iron-maiden
  (define-keyboard "HHKB"
                   :path #P"/dev/input/by-id/usb-Topre_Corporation_HHKB_Professional-event-kbd")
  (define-keyboard "Pedal3"
                   :path #P"/dev/input/by-id/usb-RDing_FootSwitch3F1.-event-mouse")
  (define-keyboard "PokerProS"
                   :path #P"/dev/input/by-id/usb-Heng_Yu_Technology_Poker_Pro_S-event-kbd")
  (define-keyboard "Poker2"
                   :path #P"/dev/input/by-id/usb-Heng_Yu_Technology_Poker_II-event-kbd")
  (define-keyboard "Poker2Sub"
                   :path #P"/dev/input/by-id/usb-Heng_Yu_Technology_Poker_II-event-if01")
  (define-keyboard "Race"
                   :path #P"/dev/input/by-id/usb-04d9_USB_Keyboard-event-kbd")
  (define-keyboard "Thinkpad"
                   :path #P"/dev/input/by-id/usb-Lite-On_Technology_Corp._ThinkPad_USB_Keyboard_with_TrackPoint-event-kbd")
  (define-keyboard "Kinesis"
                   :path #P"/dev/input/by-id/usb-05f3_0007-event-kbd")
  (define-keyboard "SinglePedal"
                   :path #P"/dev/input/by-id/usb-MKEYBOARD_3011-event-mouse")
  (define-mouse    "PowerMate"
                   :path #P"/dev/input/by-id/usb-Griffin_Technology__Inc._Griffin_PowerMate-event-if00")
  (define-mouse "SBT"
                :path #P"/dev/input/by-id/usb-Kensington_Kensington_Slimblade_Trackball-event-mouse")
  (define-mouse "RingMouse"
                :name "Genius Ring Mouse nRF")
  (define-keyboard "AnkerBTKB"
                   :name "Anker Bluetooth Keyboard")
  (define-keyboard "LaserKB"
                   :name "ELECOM TK-PBL042")
  (define-keyboard "Internal"
                   :name "AT Translated Set 2 keyboard")

  ; safety
  (let ((ring (imrb:make-ring-buffer 10)))
    (define-processor
      (for-keyboard
        (when-key-down
          (when (= code key-esc)
            (imrb:put-to-buffer ring msec)
            (when-let (next (imrb:next-buffer ring))
              (when (< (- msec next) 2000)
                (imrb:clear-all-buffer ring)
                (sb-ext:exit))))))))

  ; pp
  (define-processor
    (when *output-mode*
      (pp t ev))
    (for-keyboard
      (key-map-to-action
        "<leftalt><leftalt><leftalt>"
        (toggle-output-mode))))

  ; ignore
  (define-processor
    (for-device "PowerMate"
      (next-event)))


  ; フットペダルを特殊キーの入力用に使用する
  (define-processor
    (for-device "SinglePedal"
      (when-key-down
        (setf *foot-pedal-pressed* t))
      (when-key-up
        (setf *foot-pedal-pressed* nil))
      (next-event))
    (when *foot-pedal-pressed*
      (for-keyboard
        (key-map-to-action "w" (imx:warp-pointer 0 -5))
        (key-map-to-action "a" (imx:warp-pointer -5 0))
        (key-map-to-action "s" (imx:warp-pointer 0 5))
        (key-map-to-action "d" (imx:warp-pointer 5 0))
        (change key-1 key-f1)
        (change key-2 key-f2)
        (change key-3 key-f3)
        (change key-4 key-f4)
        (change key-5 key-f5)
        (change key-6 key-f6)
        (change key-7 key-f7)
        (change key-8 key-f8)
        (change key-9 key-f9)
        (change key-0 key-f10)
        (change key-j key-down)
        (change key-k key-up)
        (change key-h key-left)
        (change key-l key-right))))

  ; Kinesis は特殊なため先に処理する
  (define-processor
    (for-device "Kinesis"

      (key-map-to-key "<rightmeta>" "<A-S-enter>")
      (key-map-to-action "<leftalt>" (toggle-output-mode))
      (key-map-to-action "<pagedown>" (toggle-xmonad-pad "zsh"))
      (key-map-to-action "<pageup>" (toggle-xmonad-pad "shell"))

      (x-and-y key-leftctrl key-esc key-leftalt)
      (x-and-y key-rightctrl key-esc key-leftalt)
      (x-and-y key-enter nil key-leftalt)
      (x-and-y key-delete key-enter key-leftalt)
      (x-and-y key-backspace key-space key-leftshift)
      (x-and-y key-apostrophe nil key-leftctrl)

      (key-map-to-key "<f1>" "<A-1>")
      (key-map-to-key "<f2>" "<A-2>")
      (key-map-to-key "<f3>" "<A-3>")
      (key-map-to-key "<f4>" "<A-4>")
      (key-map-to-key "<f5>" "<A-5>")
      (key-map-to-key "<f6>" "<A-6>")
      (key-map-to-key "<f7>" "<A-7>")
      (key-map-to-key "<f8>" "<A-8>")
      (key-map-to-key "<f9>" "<A-9>")
      (key-map-to-key "<f10>" "<A-0>")

      (change key-capslock key-leftctrl)))

  ; pedals
  (define-processor
    (for-device "Pedal3"
      (pedal-shell im dev ev)
      (pedal-ranger im dev ev)
      (pedal-calc im dev ev)))

  ; change keys
  (define-processor
    ; TypeMatrix は特殊なため先に処理する
    (for-device "TypeMatrix"
      (change key-backspace key-esc)
      (change key-capslock key-leftalt)
      (change key-leftmeta key-leftalt)
      (change key-compose key-leftalt)
      (change key-rightctrl key-leftalt)
      (change key-left key-leftalt)
      (change key-leftshift key-leftctrl))

    ; 全キーボード
    (for-keyboard
      (change key-leftmeta key-leftalt)
      (change key-capslock key-leftctrl))

    ; 右上のキーを以下のようにする
    ; [equal][backslash]
    ;   [r-brace][grave]
    ;        [e n t e r]

    ; 対象配列
    ; 左      右
    ; `       Backspace
    ;         Backslash
    (for-device "Race"
      (change key-grave key-esc)
      (change key-backspace key-backslash)
      (change key-backslash key-grave))

    ; 対象配列
    ; 右
    ; Backspace
    ; Backslash
    (for-device ("PokerProS" "Poker2" "AnkerBTKB" "Thinkpad" "Internal")
      (change key-backspace key-backslash)
      (change key-backslash key-grave))

    ; for application
    (for-keyboard
      (when-key-press
        (for-window-class "sxiv"
          (change key-k key-p)
          (change key-j key-n)))))

  ; SandS
  (define-processor
    (x-and-y key-space nil key-leftshift))

  ; key-map
  (define-processor
    (for-keyboard
      (key-map-to-action "<home>" (imx:warp-pointer 5 0))
      (key-map-to-action "<end>" (imx:warp-pointer -5 0))
      (key-map-to-action "<pageup>" (imx:warp-pointer 0 5))
      (key-map-to-action "<pagedown>" (imx:warp-pointer 0 -5))

      (for-window-class "chromium"
        (key-map "<C-S-w>" "<C-w>")
        (key-map "<C-w>" "<backspace>")
        (key-map "<C-h>" "<backspace>"))
      (for-window-class ("Navigator" "Dialog")
        (key-map "<C-h>" "<backspace>"))))

  ; test
  ; (define-processor
  ;   (for-device "RingMouse"
  ;     (/ 0 0)))

  ; rhythm
  (define-processor
    (for-keyboard
      (rhythm-map
        key-leftshift '(1 1 1)
        (press-key im "<A-C-f1>"))
      (rhythm-map
        key-rightshift '(1 1 1)
        (press-key im "<A-C-f7>"))
      (rhythm-map
        key-leftctrl '(100 30)
        (slock)))))