AceCentre / MorseWriter

Small app to convert 1 or 2 key presses from morse into text and keyboard-mapped keys
23 stars 4 forks source link

Check keyboard faulting on macOS #42

Closed willwade closed 4 months ago

willwade commented 5 months ago

https://github.com/boppreh/keyboard/issues/619

willwade commented 5 months ago
root - DEBUG - [Window init] Initial visibility status: True
Process 44316 stopped
* thread #12, name = 'KeyListenerThread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1938dc828)
    frame #0: 0x00000001938dc828 libdispatch.dylib`_dispatch_assert_queue_fail + 120
libdispatch.dylib`:
->  0x1938dc828 <+120>: brk    #0x1

libdispatch.dylib`dispatch_assert_queue_not:
    0x1938dc82c <+0>:   pacibsp 
    0x1938dc830 <+4>:   stp    x29, x30, [sp, #-0x10]!
    0x1938dc834 <+8>:   mov    x29, sp
Target 0: (python) stopped.
(lldb) bt
* thread #12, name = 'KeyListenerThread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1938dc828)
  * frame #0: 0x00000001938dc828 libdispatch.dylib`_dispatch_assert_queue_fail + 120
    frame #1: 0x00000001938dc7b0 libdispatch.dylib`dispatch_assert_queue + 196
    frame #2: 0x000000019e30e860 HIToolbox`islGetInputSourceListWithAdditions + 160
    frame #3: 0x000000019e310e9c HIToolbox`isValidateInputSourceRef + 92
    frame #4: 0x000000019e310d5c HIToolbox`TSMGetInputSourceProperty + 44
    frame #5: 0x00000001a4a51050 libffi.dylib`ffi_call_SYSV + 80
    frame #6: 0x00000001a4a59ae0 libffi.dylib`ffi_call_int + 1212
    frame #7: 0x00000001008479fc _ctypes.cpython-311-darwin.so`_ctypes_callproc + 1332
    frame #8: 0x00000001008402c4 _ctypes.cpython-311-darwin.so`PyCFuncPtr_call + 1276
    frame #9: 0x00000001009c5ff4 libpython3.11.dylib`_PyObject_MakeTpCall + 344
    frame #10: 0x0000000100aa59e8 libpython3.11.dylib`_PyEval_EvalFrameDefault + 35800
    frame #11: 0x0000000100a9cd70 libpython3.11.dylib`_PyEval_Vector + 200
    frame #12: 0x00000001009c5e0c libpython3.11.dylib`_PyObject_FastCallDictTstate + 272
    frame #13: 0x00000001009c6b54 libpython3.11.dylib`_PyObject_Call_Prepend + 148
    frame #14: 0x0000000100a330d8 libpython3.11.dylib`slot_tp_init + 188
    frame #15: 0x0000000100a28a70 libpython3.11.dylib`type_call + 424
    frame #16: 0x00000001009c5ff4 libpython3.11.dylib`_PyObject_MakeTpCall + 344
    frame #17: 0x0000000100aa59e8 libpython3.11.dylib`_PyEval_EvalFrameDefault + 35800
    frame #18: 0x0000000100a9cd70 libpython3.11.dylib`_PyEval_Vector + 200
    frame #19: 0x00000001009c5e0c libpython3.11.dylib`_PyObject_FastCallDictTstate + 272
    frame #20: 0x00000001009c6b54 libpython3.11.dylib`_PyObject_Call_Prepend + 148
    frame #21: 0x0000000100a330d8 libpython3.11.dylib`slot_tp_init + 188
    frame #22: 0x0000000100a28a70 libpython3.11.dylib`type_call + 424
    frame #23: 0x00000001009c5ff4 libpython3.11.dylib`_PyObject_MakeTpCall + 344
    frame #24: 0x0000000100aa59e8 libpython3.11.dylib`_PyEval_EvalFrameDefault + 35800
    frame #25: 0x0000000100a9cd70 libpython3.11.dylib`_PyEval_Vector + 200
    frame #26: 0x00000001009c8b04 libpython3.11.dylib`method_vectorcall + 308
    frame #27: 0x00000001005ce354 sip.cpython-311-darwin.so`sip_api_call_procedure_method + 100
    frame #28: 0x0000000100f0427c QtCore.abi3.so`sipQThread::run() + 112
    frame #29: 0x00000001017c4090 QtCore`___lldb_unnamed_symbol7164 + 284
    frame #30: 0x0000000193a8af94 libsystem_pthread.dylib`_pthread_start + 136
willwade commented 5 months ago

Its definitley tricky this. TISGetInputSourceProperty is causing the seg fault. Here is some interesting code..

Note if we change that byte code returned its all returning with None as the input types

import ctypes
import objc
from Foundation import NSDictionary

Carbon = ctypes.CDLL('/System/Library/Frameworks/Carbon.framework/Carbon')

# Define the type of the TISCreateInputSourceList function
Carbon.TISCreateInputSourceList.restype = ctypes.c_void_p
Carbon.TISCreateInputSourceList.argtypes = [ctypes.c_void_p, ctypes.c_bool]

# Define the type of the TISGetInputSourceProperty function
Carbon.TISGetInputSourceProperty.restype = ctypes.c_void_p
Carbon.TISGetInputSourceProperty.argtypes = [ctypes.c_void_p, ctypes.c_void_p]

# Define the kTISPropertyInputSourceID constant
# Define the kTISPropertyInputSourceID constant
# Define the kTISPropertyInputSourceID constant
kTISPropertyInputSourceID = ctypes.c_void_p.in_dll(Carbon, 'kTISPropertyInputSourceID')
kTISPropertyInputSourceID = objc.objc_object(c_void_p=kTISPropertyInputSourceID)
# Create a list of all input sources
input_sources = Carbon.TISCreateInputSourceList(None, False)

from ctypes import CFUNCTYPE, c_void_p, c_bool

# Define the CFArrayGetCount function
CFArrayGetCount = CFUNCTYPE(c_void_p, c_void_p)(('CFArrayGetCount', Carbon))

# Define the CFArrayGetValueAtIndex function
CFArrayGetValueAtIndex = CFUNCTYPE(c_void_p, c_void_p, c_void_p)(('CFArrayGetValueAtIndex', Carbon))

# Create a list of all input sources
input_sources = Carbon.TISCreateInputSourceList(None, False)

# Get the number of input sources
num_sources = CFArrayGetCount(input_sources)

# Define the kTISPropertyInputSourceID constant
kTISPropertyInputSourceID = ctypes.c_void_p.in_dll(Carbon, 'kTISPropertyInputSourceID')

# Print details about each input source
for i in range(num_sources):
    source = CFArrayGetValueAtIndex(input_sources, i)
    source_id_ptr = Carbon.TISGetInputSourceProperty(source, kTISPropertyInputSourceID)
    if source_id_ptr is not None:
        source_id = ctypes.c_char_p(source_id_ptr).value
        print(f"Input source {i}: {source_id}")