본문 바로가기
#컴퓨터 과학 [Computer Science]/운영체제 (Operating System)

[OS - 🍎 macOS] macOS mouseDown, mouseUp, keyDown, keyUp event 설정방법 (NSViewController not responds to mouseDown, mouseUp, keyDown, keyUp event)

by cy_mos 2020. 3. 29.
반응형

🗂 Handling Mouse, Keyboad Events Swift Source Code

override func viewDidLoad() {
        super.viewDidLoad()
 
        NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] in
            guard let self = self else { return nil }
 
            self.keyDown(with: $0)
            return $0
        }
        NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { [weak self] in
            guard let self = self else { return nil }
 
            self.mouseDown(with: $0)
            return $0
        }
}

// MARK: - Event Method
override func keyDown(with event: NSEvent) {
	super.keyDown(with: event)
}

override func mouseDown(with event: NSEvent) {
	super.mouseDown(with: event)
}

🚀 REFERENCE

 

Handling Mouse Events

Handling Mouse Events Mouse events are one of the two most frequent kinds of events handled by an application (the other kind being, of course, key events). Mouse clicks—which involve a user pressing and then releasing a mouse button—generally indicate sel

developer.apple.com

 

NSResponder - AppKit | Apple Developer Documentation

Informs the receiver that the user has pressed or released a modifier key (Shift, Control, and so on).

developer.apple.com

반응형

댓글