Jump to content

I would like a Kanata v1.6.0 script (which is compatible with Windows 7) that allows me to program a secondary keyboard configured as a numpad.

I want to assign keyboard shortcuts in two different modes:

  • When Num Lock is active
  • When Num Lock is inactive

This gives me a total of 20 programmable keys (10 keys × 2 modes).

The shortcuts will trigger AutoHotkey scripts running in the background (e.g., Ctrl + C , etc.).

URL of the repository : https://github.com/jtroo/kanata

 

71Q8MYE274L._AC_SL1500_.jpg

Link to comment
https://linustechtips.com/topic/1608847-kanata-v160-script/
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Didn't test this at all, but maybe something like this?

 

Quick reminder to look over code before running it, especially when provided by a stranger from the internet. At least ask ChatGPT what it does first.

;; ─── Global settings ──────────────────────────────────────────────────────────
(defcfg
  ;; Make sure unmapped keys still pass through
  process-unmapped-keys yes
)

;; ─── Alias definitions ────────────────────────────────────────────────────────
(defalias
  ;; Layer-toggle helpers: send NumLock, then switch base layer
  on  (multi numlock (layer-switch num-active))
  off (multi numlock (layer-switch base))

  ;; Macros for NumLock-active mode (20xx = placeholder for your AHK hotkeys)
  m1  (macro C-c)    ;; Send Ctrl +C → picked up by your AHK
  m2  (macro C-v)
  m3  (macro C-x)
  m4  (macro C-z)
  m5  (macro C-s)
  m6  (macro C-p)
  m7  (macro C-a)
  m8  (macro C-f)
  m9  (macro C-t)
  m0  (macro C-e)

  ;; Macros for NumLock-inactive mode
  n1  (macro C-1)
  n2  (macro C-2)
  n3  (macro C-3)
  n4  (macro C-4)
  n5  (macro C-5)
  n6  (macro C-6)
  n7  (macro C-7)
  n8  (macro C-8)
  n9  (macro C-9)
  n0  (macro C-0)
) 

;; ─── Source layout ────────────────────────────────────────────────────────────
;; Only the keypad keys need to be declared; all other keys will pass through.
(defsrc
  kp7 kp8 kp9
  kp4 kp5 kp6
  kp1 kp2 kp3
  kp0
)

;; ─── Layers ───────────────────────────────────────────────────────────────────
;; Base layer (NumLock OFF)
(deflayer base
  ;; Pressing NumLock here sends NumLock → toggles to the num-active layer
  NumLock @on

  ;; Map each keypad key to its “inactive” macro
  kp7 @n7
  kp8 @n8
  kp9 @n9
  kp4 @n4
  kp5 @n5
  kp6 @n6
  kp1 @n1
  kp2 @n2
  kp3 @n3
  kp0 @n0
)

;; NumLock-active layer
(deflayer num-active
  ;; Pressing NumLock here sends NumLock → toggles back to base
  NumLock @off

  ;; Map each keypad key to its “active” macro
  kp7 @m7
  kp8 @m8
  kp9 @m9
  kp4 @m4
  kp5 @m5
  kp6 @m6
  kp1 @m1
  kp2 @m2
  kp3 @m3
  kp0 @m0
)

 

The macros are done as a simple macro action that emits Ctrl+… so your background AutoHotkey scripts can pick them up. YOU PROBABLY WANT TO CHANGE WHICH SHORTCUT IT SENDS TO BE INTERCEPTED. The number keys are just the default keypad scan codes.


To run:

- save this as numpad.kbd

- launch with kanata.exe -c C:<insert the path here>numpad.kbd

 

Hope this helps! Let me know if you have any questions.

Link to comment
https://linustechtips.com/topic/1608847-kanata-v160-script/#findComment-16714509
Share on other sites

Link to post
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×