parent
653e746172
commit
3d5a8ecb96
@ -0,0 +1,30 @@ |
|||||||
|
# Empty method that does nothing (placeholder for keyhooks) |
||||||
|
def nullmethod |
||||||
|
return |
||||||
|
end |
||||||
|
|
||||||
|
|
||||||
|
# Handler for key events |
||||||
|
class KeyHook |
||||||
|
attr_reader :nullmethod_ptr |
||||||
|
attr_accessor :key_hooks |
||||||
|
|
||||||
|
def initialize |
||||||
|
@nullmethod_ptr = method(:nullmethod) |
||||||
|
|
||||||
|
@key_hooks = Hash.new(Hash.new(@nullmethod_ptr)) |
||||||
|
# Each keyhook contains a hash of method pointers |
||||||
|
end |
||||||
|
|
||||||
|
def add(hook, event_name=:main, method_sym=:nullmethod) |
||||||
|
self.key_hooks[hook][event_name] = method(method_sym) |
||||||
|
end |
||||||
|
|
||||||
|
def remove(hook, event_name=:main) |
||||||
|
self.key_hooks[hook][event_name] = self.nullmethod_ptr |
||||||
|
end |
||||||
|
|
||||||
|
def call(hook, event_name, *args) |
||||||
|
self.key_hooks[hook][event_name].call(*args) |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue