1

I am using a custom view class, which is a subclass of NSControl. This view is a key view and needs to handle keyDown event including space/tab key.

But, when Full Keyboard Access is enabled at System Settings app > Accessibility > Keyboard, the custom view cannot receive space/tab keyDown event. MacOS seems to interrupt space/tab key event to control keyboard focus.

Screenshot: Full Keyboard Access setting at Accessibility

On the other hand, NSTextView seems to be able to receive space/tab key events as follows even when Full Keyboard Access is enabled.

  1. When user presses tab key from the previous view, keyboard focus moves to the NSTextView.
  2. When user presses tab key at the NSTextView before inputing any letter, keyboard focus moves to the next view.
  3. When user presses tab key at the NSTextView after inputing any letter, a tab letter is input.
  4. When user presses space key at the NSTextView, a space letter is input.

I want to do the same behavior as NSTextView. But, I could not find the way to receive space/tab keyDown event when Full Keyboard Access is enabled.

How to receive keyDown event for space/tab key when Full Keyboard Access is enabled?

  • I checked the following post, but it seems that the answer only explains how to set key view loop so that keyboard focus can be moved.

    Disable Full Keyboard Access for App

  • I confirmed this issue happens with macOS 13.2.1 and 12.5.

  • There was an old "Full Keyboard Access" setting at System Settings app > Keyboard > Shortcuts in older macOS. This issue did not happen when the old Full Keyboard Access was enabled.


I tested the following minimal test code.

CustomView.m

@implementation CustomView
- (BOOL)acceptsFirstResponder {
    return YES;
}
- (BOOL)canBecomeKeyView {
    return YES;
}
- (void)keyDown:(NSEvent *)event {
    NSLog(@"keyDown");
}
- (void)mouseDown:(NSEvent *)event {
    [[self window] makeFirstResponder:self];
}
- (BOOL)isAccessibilityElement {
    return YES;
}
- (BOOL)isAccessibilityEnabled {
    return YES;
}
- (NSAccessibilityRole)accessibilityRole {
    return NSAccessibilityTextFieldRole;
}
@end

CustomView.h

@interface CustomView : NSControl
@end

ViewController.m

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [[[self view] window] makeFirstResponder:self.customView1];
}
@end

Expected result: The custom view can receive space/tab keyDown event.

Actual result: The custom view cannot receive space/tab keyDown event.

Daisuke K.
  • 11
  • 2

1 Answers1

0

I could resolve this issue after I implement the following methods of NSAccessibility API. (I am not sure which methods are mandatory to resolve this issue. At least, accessibilityValue and setAccessibilityValue are mandatory.)

isAccessibilityElement
isAccessibilityEnabled
accessibilityValue
setAccessibilityValue
isAccessibilityFocused
accessibilityInsertionPointLineNumber
accessibilityNumberOfCharacters
accessibilitySelectedText
accessibilitySelectedTextRange
setAccessibilitySelectedTextRange
accessibilitySelectedTextRanges
accessibilityVisibleCharacterRange
accessibilityStringForRange
accessibilityAttributedStringForRange
accessibilityFrameForRange
accessibilityLineForIndex
accessibilityRangeForIndex
accessibilityStyleRangeForIndex
accessibilityRangeForLine
accessibilityFocusedUIElement
accessibilityHitTest
Daisuke K.
  • 11
  • 2