I'm not sure why you would assume that a keyboard event has a window number. When you create a keyboard event with CGEventCreateKeyboardEvent, you don't specify a window or a mouse location. And the global event monitor may see events before applications have begun to dispatch them.
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: