0 && cgsEvent.type <= kCGSLastEventType"-6ren"> 0 && cgsEvent.type <= kCGSLastEventType"-有时,主要是在重负载时,我会收到以下错误: 2013-04-23 23:53:13.595 MusicPlayer[74705:6303] unrecognized type is -2 2013-0-6ren">
gpt4 book ai didi

python - "error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType"

转载 作者:行者123 更新时间:2023-12-03 17:54:19 39 4
gpt4 key购买 nike

有时,主要是在重负载时,我会收到以下错误:

2013-04-23 23:53:13.595 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-23 23:53:14.686 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:40:47.358 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:40:47.561 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:42:49.016 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:42:49.017 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:42:53.689 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:42:53.689 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:43:01.091 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:43:01.091 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:43:06.840 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:43:06.840 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
new song: Tiestö - Reepublic, 00:15, mp3, 125 kbit/s, 233 KB
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
line: Quartz.CFRunLoopRun()
locals:
Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType

相关代码:

    import AppKit, Quartz
from AppKit import NSSystemDefined
pool = AppKit.NSAutoreleasePool.alloc().init()

self.runLoopRef = Quartz.CFRunLoopGetCurrent()

while True:
# https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
tap = Quartz.CGEventTapCreate(
Quartz.kCGSessionEventTap, # Quartz.kCGSessionEventTap or kCGHIDEventTap
Quartz.kCGHeadInsertEventTap, # Insert wherever, we do not filter
Quartz.kCGEventTapOptionDefault, #Quartz.kCGEventTapOptionListenOnly,
Quartz.CGEventMaskBit(NSSystemDefined), # NSSystemDefined for media keys
self.eventTap,
None
)
assert tap

# Create a runloop source and add it to the current loop
runLoopSource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
Quartz.CFRunLoopAddSource(
self.runLoopRef,
runLoopSource,
Quartz.kCFRunLoopDefaultMode
)

# Enable the tap
Quartz.CGEventTapEnable(tap, True)

try:
# and run! This won't return until we exit or are terminated.
Quartz.CFRunLoopRun()
except Exception:
# I got this one here once:
# error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
sys.excepthook(*sys.exc_info())
continue # rerun

# this is a regular quit
break

del pool

该异常主要伴随着 GUI 线程的挂起(这是我不想忽略它的主要原因 - 因为它可能非常值得注意)。

最佳答案

来自here ,我得到了有用的信息:

Actually an event type CGEventType is defined in CGEventType.h as unsigned 32-bit integer. So your -2 is actually 0xFFFFFFFE. In CGEventType.h that's defined as kCGEventTapDisabledByTimeout. There's a comment just about this that says:

  /* Out of band event types. These are delivered to the event tap callback
to notify it of unusual conditions that disable the event tap. */
kCGEventTapDisabledByTimeout = 0xFFFFFFFE,
kCGEventTapDisabledByUserInput = 0xFFFFFFFF

So it looks like your event tap is timing out. That's why your not getting anymore events after this.

在 Python 中,在事件点击中,您可以像这样检查这种情况:

def eventTap(self, proxy, type_, event, refcon):
if type_ < 0 or type_ > 0x7fffffff:
# handle it ...

请注意,在获得此类事件类型后,事件点击将被禁用。因此您可能想重新启动事件循环。

关于python - "error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16190680/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com