Don't like ads? PRO users don't see any ads ;-)
Guest

farhaven

By: a guest on Nov 21st, 2008  |  syntax: Lua  |  size: 0.93 KB  |  hits: 81  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. local capi = {
  2.     keygrabber = keygrabber
  3. }
  4. local wibox = wibox
  5. local widget = widget
  6. local button = button
  7. local print = print
  8.  
  9. module("keytest")
  10. local text = ""
  11.  
  12. function grabber_setup(widget)
  13.     capi.keygrabber.run(function (mod, key)
  14.         print(key)
  15.         if key:len() == 1 then
  16.             text = text .. key
  17.         elseif key == "BackSpace" and text:len() > 0 then
  18.             text = text:sub(1, text:len() - 1)
  19.         end
  20.         widget.text = text
  21.         return true
  22.     end)
  23. end
  24.  
  25. function run()
  26.     local wb = wibox({ position = "floating" })
  27.     local wi = widget({ type = "textbox", align = "flex" })
  28.     wb.widgets = { wi }
  29.     wb:geometry({ x = 100, y = 100, width = 200, height = 20 })
  30.     wb.screen = 1
  31.     wi.buttons = { button({ }, 1, function () capi.keygrabber.stop() end),
  32.                    button({ }, 3, function () grabber_setup(wi) end)
  33.                  }
  34.     grabber_setup(wi)
  35. end