HomeiOS Developmentios - UIResponder's pressBegan does not register character press

ios – UIResponder’s pressBegan does not register character press


I am going through a bizarre situation. I overrode func pressesBegan(_ presses: Set<UIPress>, with occasion: UIPressesEvent?) in my opinion to deal with key presses. It really works nice with character key presses. However as quickly as I attempt to use modifier keys (cmd, shift, and many others.), it stops registering the precise character key.

  • Urgent character keys whereas holding different character keys works nice
  • Urgent modifier keys whereas holding different modifier keys works nice
  • Urgent character keys whereas holding modifier keys does not register the character keys, modifier keys are nonetheless registered. Solely the primary press of every character is registered, after that, I’ve to launch the modifier, press that character key as soon as (not registered right here), that appears to reset one thing after which modifier + character works once more as soon as.

Right here is the code:

class SomeView: UIView {
  override var canBecomeFirstResponder: Bool { true }

  init() {
    tremendous.init(body: .zero)
    becomeFirstResponder()
  }

  override func pressesBegan(_ presses: Set<UIPress>, with occasion: UIPressesEvent?) {
    print(presses.first?.key?.keyCode.rawValue, presses.depend)
  }
}

With this motion sequence:

  • Press Cmd and maintain it (1)
  • Press z (2)
  • Press z (3)
  • Press z (4)
  • Launch Cmd (5)
  • Press z (6)
  • Press z (7)
  • Press Cmd and maintain it (8)
  • Press z (9)
  • Press z (10)

It would produce this output:

Non-obligatory(227) 1 // (1)
Non-obligatory(29) 1 // (2), (3) and (4) are misplaced. (5) does not do something as I do not override pressEnded
Non-obligatory(29) 1 // (7), (6) is misplaced
Non-obligatory(227) 1 // (8)
Non-obligatory(29) 1 // (9), (10) is misplaced

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments