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 (1301B)


      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] = function()
     36     keyNoDelay({}, "left")
     37   end,
     38   [91] = function()
     39     keyNoDelay({}, "up")
     40   end,
     41   [88] = function()
     42     keyNoDelay({}, "right")
     43   end,
     44   [84] = function()
     45     keyNoDelay({}, "down")
     46   end,
     47   [89] = function()
     48     keyNoDelay({}, "home")
     49   end,
     50   [83] = function()
     51     keyNoDelay({}, "end")
     52   end,
     53   [71] = function()
     54     keypad_cursor:exit()
     55   end,
     56 }
     57 
     58 for k, f in pairs(binds) do
     59   keypad_cursor:bind({}, k, f, nil, f)
     60 end