dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

numpad-cursor.lua (1300B)


      1 local icons = {
      2   [[ASCII:
      3 2.................3
      4 ...................
      5 ...................
      6 ...................
      7 ...................
      8 ...................
      9 ...................
     10 ...................
     11 ...................
     12 1.................4]],
     13 }
     14 
     15 local keypad_cursor = hs.hotkey.modal.new({}, 71)
     16 
     17 -- When enabling, show a menubar icon
     18 function keypad_cursor:entered()
     19   keypad_cursor._menubar_icon = hs.menubar.new()
     20   keypad_cursor._menubar_icon:setTitle("NK")
     21   keypad_cursor._menubar_icon:setIcon(icons[1])
     22 end
     23 
     24 -- When disabling, hide the menubar icon
     25 function keypad_cursor:exited()
     26   keypad_cursor._menubar_icon:delete()
     27 end
     28 
     29 local keyNoDelay = function(modifiers, character)
     30   hs.eventtap.event.newKeyEvent(modifiers, string.lower(character), true):post()
     31   hs.eventtap.event.newKeyEvent(modifiers, string.lower(character), false):post()
     32 end
     33 
     34 local binds = {
     35   [86] = "left",
     36   [91] = "up",
     37   [88] = "right",
     38   [84] = "down",
     39   [89] = "home",
     40   [83] = "end",
     41 }
     42 
     43 local modifiers = { {}, { "shift" } }
     44 
     45 for k, c in pairs(binds) do
     46   for _, mod in pairs(modifiers) do
     47     local f = function()
     48       keyNoDelay(mod, c)
     49     end
     50     keypad_cursor:bind(mod, k, f, nil, f)
     51   end
     52 end
     53 
     54 keypad_cursor:bind(
     55   {},
     56   71,
     57   function()
     58     keypad_cursor:exit()
     59   end,
     60   nil,
     61   function()
     62     keypad_cursor:exit()
     63   end
     64 )