You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import AppKit
import Omnia
classMyWindow:NSWindow{overridefunc keyDown(with event:NSEvent){
super.keyDown(with: event)
if isKey(NSDeleteCharacter, event: event){NotificationCenter.default.post(Notification(name:.didKeyboardDeleteItem))}else if isKey(NSUpArrowFunctionKey, event: event){print("up")}else if isKey(NSDownArrowFunctionKey, event: event){print("down")}else if isKey(NSLeftArrowFunctionKey, event: event){print("left")}else if isKey(NSRightArrowFunctionKey, event: event){print("right")}}privatefunc isKey(_ key:Int, event:NSEvent)->Bool{
if let scalar =UnicodeScalar(key){return event.characters ==String(scalar)}else{return false
}}}
Another way is to listen to
NSEvent.addLocalMonitorForEvents(matching:.keyDown){ event in
if handled(with: $0){returnnil}return event
}
Or create our own inspector
classMyWindow:NSWindow{overridefunc keyDown(with event:NSEvent){
if !EventService.shared.inspect(event){
super.keyDown(with: event)}}overridevarcanBecomeKey:Bool{ true }overridevarcanBecomeMain:Bool{ true }overridevaracceptsFirstResponder:Bool{ true }overridefunc becomeFirstResponder()->Bool{ true }}
import AppKit
import Omnia
import KeyboardShortcuts
finalclassEventService{staticletshared=EventService()privatevarcombos:[Combo]=[]privateletdebouncer=Debouncer(delay: 0.1)func register(_ combo:Combo){
combos.append(combo)}func inspect(_ event:NSEvent)->Bool{
for combo in combos {
if combo.match(event){self.debouncer.run{
combo.action()}return true
}}return false
}}extensionEventService{structCombo{letmodifier:NSEvent.ModifierFlags?letkeyCode:KeyboardShortcuts.Keyletaction:()->Voidfunc match(_ event:NSEvent)->Bool{
if let modifier = modifier,
!event.modifierFlags.contains(modifier){return false
}
if event.keyCode != keyCode.rawValue {return false
}return true
}}}
The text was updated successfully, but these errors were encountered:
Another way is to listen to
Or create our own inspector
The text was updated successfully, but these errors were encountered: