about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-07-07 18:50:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-07-07 18:50:42 -0700
commita995471ebc95411c45c2b6d656be4c9091c8b1a0 (patch)
tree5bf04067fb827412b0916e4ed0a98182e0d70b1a
parentad35894b923ebd4611a322fac473720d8abf1e0b (diff)
parent9df1c3f997e04194edc16db4999d204ea46332ff (diff)
downloadview.love-a995471ebc95411c45c2b6d656be4c9091c8b1a0.tar.gz
Merge lines.love
-rw-r--r--keychord.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/keychord.lua b/keychord.lua
index 16fa48d..f1b6a59 100644
--- a/keychord.lua
+++ b/keychord.lua
@@ -12,6 +12,11 @@ function App.keypressed(key, scancode, isrepeat)
 end
 
 function App.combine_modifiers(key)
+  if love.keyboard.isModifierActive then  -- waiting for LÖVE v12
+    if key:match('^kp') then
+      key = App.translate_numlock(key)
+    end
+  end
   local result = ''
   if App.ctrl_down() then
     result = result..'C-'
@@ -53,6 +58,38 @@ function App.is_cursor_movement(key)
   return array.find({'left', 'right', 'up', 'down', 'home', 'end', 'pageup', 'pagedown'}, key)
 end
 
+-- mappings only to non-printable keys; leave out mappings that textinput will handle
+Numlock_off = {
+  kp0='insert',
+  kp1='end',
+  kp2='down',
+  kp3='pagedown',
+  kp4='left',
+  -- numpad 5 translates to nothing
+  kp6='right',
+  kp7='home',
+  kp8='up',
+  kp9='pageup',
+  ['kp.']='delete',
+  -- LÖVE handles keypad operators in textinput
+  -- what's with the `kp=` and `kp,` keys? None of my keyboards have one.
+  -- Hopefully LÖVE handles them as well in textinput.
+  kpenter='enter',
+  kpdel='delete',
+}
+Numlock_on = {
+  kpenter='enter',
+  kpdel='delete',
+}
+function App.translate_numlock(key)
+  if love.keyboard.isModifierActive('numlock') then
+    return Numlock_on[key] or key
+  else
+    return Numlock_off[key] or key
+  end
+  return key
+end
+
 array = {}
 
 function array.find(arr, elem)