local identifier = os.registerShortcut(keys.leftCtrl, keys.a)
local event, id = os.pullEvent("key_shortcut")
if id == identifier then
print("Ctrl-A pressed")
end
The registerShortcut function takes a variable number of arguments. There must be at least one modifier key and only one non-modifier key. Once one of the modifier keys is pressed, the modifiers currently pressed are tracked by the client until a non-modifier is pressed. If the key combo pressed matches the registered shortcut, the server is notified of the shortcut being pressed which issues the event to the Lua environment.
Also, perhaps in order to allow right/left ctrl equivalency (or any other key that appears twice on the keyboard), you can pass a table in place of a key argument, containing all equivalent keys.
local identifier = os.registerShortcut( { keys.leftCtrl, keys.rightCtrl }, keys.a)
local event, id = os.pullEvent("key_shortcut")
if id == identifier then
print("Ctrl-A pressed")
end
This way you don't have to register a shortcut for every possible combination of left/right versions of desired keys.
EDIT: One more thing, if the same keyboard shortcut is registered twice, two events are issued. One for each shortcut identifier. Can't think of a better way around this problem…
EDIT2: Actually, the simple solution would be returning the identifier from the first shortcut when the second one is registered. And then, if two shortcuts can be the same, but might not, two identifiers are made and events for both are sent. So a {leftCtrl,rightCtrl}+a and a leftCtrl+a wouldn't share an identifier, but if leftCtrl+a was pressed, an event for both identifiers would be sent. While if {leftCtrl,rightCtrl}+a is registered twice (there'd need to be some logic programmed to determine equivalency in case the tables were in a different order or something), both registrations return the same identifier.