export function attachKeyboardListener(dotNetHelper) {
    const handler = (e) => {
        // Exclude inputs, textareas, etc.
        const activeNode = document.activeElement ? document.activeElement.nodeName.toLowerCase() : '';
        if (activeNode === 'input' || activeNode === 'textarea') return;

        if (e.key === 'f' || e.key === 'F') {
            dotNetHelper.invokeMethodAsync('OnFocusKeypressed');
        }
    };
    
    window.addEventListener('keydown', handler);
    return handler;
}

export function detachKeyboardListener(handler) {
    if (handler) {
        window.removeEventListener('keydown', handler);
    }
}
