Isoraqathedh

keyboard string

Mar 11th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. page = 1
  2.  
  3. function OnEvent(event, arg, family)
  4.     OutputLogMessage("event = %s, arg = %s, family = %s\n", event, arg, family);
  5.     modeNumber = GetMKeyState()
  6.     if (event == "M_RELEASED" and arg == 2 and family == "lhc") then
  7.         ClearLCD()
  8.         OutputLCDMessage("Pagination mode M2 activated.")
  9.         OutputLCDMessage("Currently at page " .. page)
  10.     end
  11.     if (event == "G_RELEASED" and GetMKeyState("lhc") == 2 and family == "lhc") then
  12.         if (arg == 24) then
  13.             page = page + 1
  14.             ClearLCD()
  15.             OutputLCDMessage("Switched to page " .. page)
  16.         elseif (arg == 23) then
  17.             if (page > 1) then
  18.                 page = page - 1
  19.                 ClearLCD()
  20.                 OutputLCDMessage("Switched to page " .. page)
  21.             else
  22.                 ClearLCD()
  23.                 OutputLCDMessage("At page 1")
  24.                 OutputLCDMessage("Cannot backtrack further")
  25.             end
  26.         else
  27.             SetBacklightColor(127, 255, 0, "lhc")
  28.             Sleep(250)
  29.             OutputLogMessage("Sending: %s/%s\n", page, arg)
  30.             -- Typed sequence 3/15/+-- (page/key/sca)
  31.             on, off = "numplus", "numminus"
  32.             if IsModifierPressed("shift")   then isShiftDown = on   else isShiftDown = off      end
  33.             if IsModifierPressed("ctrl")    then isControlDown = on else isControlDown = off    end
  34.             if IsModifierPressed("alt")     then isAltDown = on     else isAltDown = off        end
  35.             local send = {pageString = page .. "n", argString = arg .. "n"} -- coerce to string
  36.             local modlist = {isShiftDown, isControlDown, isAltDown}
  37.             -- send the keys
  38.             for k, v in pairs(send) do
  39.                 for i = 1, #v - 1 do
  40.                     local c = v:sub(i,i)
  41.                     PressAndReleaseKey("num" .. c)
  42.                 end
  43.                 PressAndReleaseKey("numslash")
  44.             end
  45.             --[[
  46.             for k, v in pairs(modlist) do
  47.                 PressAndReleaseKey(v)
  48.             end]]
  49.             PressAndReleaseKey("numminus", "numminus", "numminus", "Enter")
  50.             SetBacklightColor(255, 255, 255, "lhc")
  51.         end
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment