Difference between revisions of "Keymon.refresh"

From OpenEUO
Jump to: navigation, search
(Created page with "== Calling Pattern == Call local km = sl.keymon(t) later keymon.refresh() == Example == local t = { ['ALT SHIFT J']= function() print('ALT SHIFT J') end, ['CTRL J'] ...")
 
m (Description)
 
Line 23: Line 23:
 
== Description ==
 
== Description ==
  
The keymon refresh method the state of every key necessary and determines which, if any, hotkey is currently pressed.  The keymon generator creates a string from the given table of hotkey=handlerfunction values to quickly assess if any handler should be called and passes this to [[loadstring]].  In the example above, the created internal function looks like:
+
The keymon refresh method checks the state of every key necessary to determine which, if any, hotkey combination is currently pressed.  The keymon generator creates a string from the given table of hotkey=handlerfunction values to quickly assess if any handler should be called and passes this to [[loadstring]].  In the example above, the created internal function used by refresh looks like:
  
 
  local gk = {getkey("ALT"),getkey("SHIFT"),getkey("CTRL"),getkey("J"),};
 
  local gk = {getkey("ALT"),getkey("SHIFT"),getkey("CTRL"),getkey("J"),};

Latest revision as of 20:59, 8 January 2011

Calling Pattern

Call

local km = sl.keymon(t)

later

keymon.refresh()

Example

local t = {
  ['ALT SHIFT J']= function() print('ALT SHIFT J') end,
  ['CTRL J']     = function() print('CTRL J')      end,
}
local km = sl.keymon(t)
while true do
  km.refresh()
  wait(30)
end
-> CTRL J
   ALT SHIFT J
   ALT SHIFT J

Description

The keymon refresh method checks the state of every key necessary to determine which, if any, hotkey combination is currently pressed. The keymon generator creates a string from the given table of hotkey=handlerfunction values to quickly assess if any handler should be called and passes this to loadstring. In the example above, the created internal function used by refresh looks like:

local gk = {getkey("ALT"),getkey("SHIFT"),getkey("CTRL"),getkey("J"),};
if  gk[1] == true and gk[2] == true and gk[3] == false and gk[4] == true then return 1 
elseif  gk[1] == false and gk[2] == false and gk[3] == true and gk[4] == true then return 2 
end;

The result of calling this function is used to look up and invoke the appropriate user supplied handler. Refresh takes no arguments and normally returns no values.

Upon Error

If one of the hotkey handler functions throws an error during evaluation, an unhandled exception will occur. In versions 0.09+, any errors thrown will be caught at the keymon.refresh level and handled according to the operant error redirection mode.

See Also