Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function key support and key repeat for external keyboards #1718

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rexx-org
Copy link

@rexx-org rexx-org commented Feb 11, 2022

For iOS 13.4 or above function key support added. Function keys include F1-F12, PgUp, PgDn, Home, End, Ins/Help and arrow keys. Unmodified, shifted and control modifiers produce relevant escape sequences based on output from infocmp xterm-256color. Further information #1708

@tbodt
Copy link
Member

tbodt commented Feb 12, 2022

The biggest problem here is that this will just break anyone with less than iOS 13.4, and iSH supports iOS 11.

@rexx-org
Copy link
Author

I can restore the current behaviour for pre 13.4 to coexist but as noted in #1708, if built with the latest XCode there will be many keys that won't work at all or produce the wrong results.

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

Two small nits, there are a couple of variables that Xcode flags as unused...

Screen Shot 2022-02-11 at 4 45 21 PM

iOS 13 is supported on all phones and iPads made in 2015 and later. It even support the iPad Air 2 and the iPhone 6S. I speak only for myself of course, but I wouldn't want to use it on anything older than that.

I believe Apple supports the ability to have multiple versions available on the App store to account for older iOS limitations. I have no clue how painful that is to support though.

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

One more issue, when built on an M1 Mac the function and control keys still do not appear to work.

Here is an example of the output I see in the lldb pane when pressing the up key.

2022-02-11 17:47:58.002371-0800 iSH[56496:1089310] Key up: invalidate Timer (null) init 0
2022-02-11 17:47:58.002471-0800 iSH[56496:1089310] Modified:  Unmodified: UIKeyInputDownArrow(19) init 0
2022-02-11 17:47:58.184929-0800 iSH[56496:1089310] Key up: invalidate Timer (null) init 0
2022-02-11 17:47:58.184998-0800 iSH[56496:1089310] Key up: invalidate Timer (null) init 0

@rexx-org
Copy link
Author

Interesting; I did all my builds on M1 Mac using Xcode 13.2.1. Can you change the debugging line that logs the key pressed to:

NSLog( @"Modified: %@ Unmodified: %@(%lu) Keycode: %ld init %d", key.characters, key.charactersIgnoringModifiers,(unsigned long)[key.charactersIgnoringModifiers length], key.keyCode, initiateKeyRepeatTimer);

so that the keyCode is displayed.

When I pressed the Down Arrow before the change I got:

Modified: UIKeyInputDownArrow Unmodified: UIKeyInputDownArrow(19) init 0

which is different to you; the "Modified:" string is different. No idea why; that is the value that iOS supplies.

For Down Arrow I now get:

Modified: UIKeyInputDownArrow Unmodified: UIKeyInputDownArrow(19) Keycode: 81 init 0

I suspect that you are not getting a valid keyCode.

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

Sure.

I just upgraded to MacOS 12.2.1, so I did a full reboot since my last attempt. I also did an apk update.

2022-02-11 19:24:22.934206-0800 iSH[18594:182899] Modified:  Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:25:05.335892-0800 iSH[18594:182899] Modified:  Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:25:22.656380-0800 iSH[18594:182899] Modified:  Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:25:24.377946-0800 iSH[18594:182899] Modified:  Unmodified: UIKeyInputDownArrow(19) Keycode: 81 init 0
2022-02-11 19:25:35.994828-0800 iSH[18594:182899] Modified: Unmodified: (0) Keycode: 227 init 0

Still not working.

I'm building from the current iSH master plus your PR. It works fine when I build for my iPad Air 3.

Here is what I get when pushing the up and down arrow keys on the iPad Air 3 keyboard

2022-02-11 19:33:15.537012-0800 iSH[12900:7161067] Modified: UIKeyInputUpArrow Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:33:17.517855-0800 iSH[12900:7161067] Modified: UIKeyInputDownArrow Unmodified: UIKeyInputDownArrow(19) Keycode: 81 init 0
2022-02-11 19:33:17.995371-0800 iSH[12900:7161067] Modified: UIKeyInputDownArrow Unmodified: UIKeyInputDownArrow(19) Keycode: 81 init 0
2022-02-11 19:33:18.454963-0800 iSH[12900:7161067] Modified: UIKeyInputUpArrow Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:33:18.741879-0800 iSH[12900:7161067] Modified: UIKeyInputUpArrow Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0
2022-02-11 19:33:19.087715-0800 iSH[12900:7161067] Modified: UIKeyInputUpArrow Unmodified: UIKeyInputUpArrow(17) Keycode: 82 init 0

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

As an aside, when I change the minimum iOS level to 13.4 in Xcode I get some potentially interesting deprecation notifications...
Screen Shot 2022-02-11 at 7 40 54 PM

@rexx-org
Copy link
Author

Sorry a bit confused. What still doesn't work? Is it running a simulator on your Mac and pressing the keys on your Mac keyboard that doesn't work, but an external keyboard connected to your iPad Air 3 does work?

The deprecations are interesting.

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

When I build with the target as the Mac the resulting binary does not have functional arrow or control keys. When I build with the target as my iPad Air 3, the arrow and control keys work fine

Screen Shot 2022-02-11 at 8 19 43 PM

.

@rexx-org
Copy link
Author

Got it. I haven't tried building for the Mac. Will try that later.

@rexx-org
Copy link
Author

When running the Mac build, none of the function keys are passed to the app, so nothing can be done about that. The arrow keys have a NumberPad modifier associated. I've removed that and the arrow keys work, but little else is sent to the app.
Trying to build for a simulator running iOS 12.4 to test pre 13.4 key handling, but get linker errors :-(

@emkey1
Copy link
Contributor

emkey1 commented Feb 12, 2022

Thank you for testing/fixing this stuff.

Some of these issues are likely Apple bugs, some the result of things having been deprecated. I don't think Apple would win any awards in the area of software Q&A, especially in the area of developer tools. :-(

@rexx-org
Copy link
Author

I have reinstated the pre iOS v13.4 external keyboard handling to coexist with the new function key handling in this PR. I tested the pre-1.34 keyboard handling on an iOS 12.4 simulator on an x86 MacBook Pro using Xcode 13.2.1 (same version as M1 that wouldn't compile). Key handling seems to work fine including arrow keys and key repeat behaviour.

@tbodt
Copy link
Member

tbodt commented Feb 12, 2022

Wondering if we can use this instead. Will take a look later today. https://developer.apple.com/documentation/uikit/uikeycommand/3780513-wantspriorityoversystembehavior?language=objc

@tbodt
Copy link
Member

tbodt commented Feb 13, 2022

Wondering if we can use this instead. Will take a look later today. developer.apple.com/documentation/uikit/uikeycommand/3780513-wantspriorityoversystembehavior?language=objc

Update: this worked: 43144e3

I think It would make sense, now, to add UIKeyCommands for the remaining function keys, and not use pressesBegan.

@rexx-org
Copy link
Author

Ok I'll change the code to extend the current mechanism.

@rexx-org
Copy link
Author

rexx-org commented Feb 14, 2022

Only problem I seem to have with this change is that unshifted alpha and number keys do not repeat. Control and shifted alpha and number keys repeat as do function and navigation keys.

Also the Backspace and Delete keys are reversed.

@0x4248
Copy link

0x4248 commented Feb 15, 2022

I tried making an issue on this #1628

@emkey1
Copy link
Contributor

emkey1 commented May 5, 2022

FYI, the pressesBegan function in the current version breaks the

External Keyboard->Send ctrl-space to terminal

Functionality. Specifically enabling the option no longer does the correct thing I haven't narrowed it down any more than that.

@chadify
Copy link

chadify commented Feb 16, 2023

Can someone please provide me the compiled binary of this PR merged with the base branch? I do not have a Mac, so I cannot build it out myself. Having key repeat would be of great convenience.

Thanks.

@emkey1
Copy link
Contributor

emkey1 commented Feb 16, 2023

Can someone please provide me the compiled binary of this PR merged with the base branch? I do not have a Mac, so I cannot build it out myself. Having key repeat would be of great convenience.

Thanks.

My fork, iSH-AOK incorporates portions of this PR. Function keys appear to work, but I haven't had luck with key repeat. Though for some odd reason, ctrl+j and ctrl+h cause key repeat to work for those two keys in both iSH and iSH-AOK, but the same is not true of the k and l keys.

@chadify
Copy link

chadify commented Feb 17, 2023

Can someone please provide me the compiled binary of this PR merged with the base branch? I do not have a Mac, so I cannot build it out myself. Having key repeat would be of great convenience.
Thanks.

My fork, iSH-AOK incorporates portions of this PR. Function keys appear to work, but I haven't had luck with key repeat. Though for some odd reason, ctrl+j and ctrl+h cause key repeat to work for those two keys in both iSH and iSH-AOK, but the same is not true of the k and l keys.

The function keys working is not useful to me as I’m using the Magic Keyboard. But, the key repeat would be very useful. Does fully incorporating this PR on the main branch makes the key repeat work? And if it does, Would it be possible if you can provide me the compiled binaries with the above feature working?

Thank you.

@8427003
Copy link

8427003 commented Jun 28, 2023

@tbodt @rexx-org This feature vim strongly needs, wait online

@8427003
Copy link

8427003 commented Jun 29, 2023

@rexx-org not support letter key repeat? i build from your branch, but vim not working, hjkl can't repeat

@yao2000
Copy link

yao2000 commented Aug 26, 2023

I am using iSH 1.3.2 (Build 494). F1-F12 still do not work. Is it expected?

@jcuberdruid
Copy link

Using version 1.3.2 on iPhone 15 and IOS 17.0.2 key press and hold pop ups occur when using a usb keyboard. Noting that arrow keys, delete, and space do repeat. But "as a vim user" cough cough originality it would be nice if h j k and L could have this feature.

@emkey1
Copy link
Contributor

emkey1 commented Sep 25, 2023

Using version 1.3.2 on iPhone 15 and IOS 17.0.2 key press and hold pop ups occur when using a usb keyboard. Noting that arrow keys, delete, and space do repeat. But "as a vim user" cough cough originality it would be nice if h j k and L could have this feature.

If you hold down the ctrl key, the h and j keys repeat, but not k and l.

I have no clue why this is, and I'm not sure if this is more useful than it is annoying but I figured it was worth mentioning.

@akwan
Copy link

akwan commented Oct 6, 2023

stumbled on this PR from searching. Would love support for repeating h j k l in vim - i use iSH on an iPad with magic keyboard.

@rija
Copy link

rija commented Jul 19, 2024

Hi @rexx-org, @tbodt

I’m wondering if there is value in splitting this PR in two PRs:

  • one PR for implementing support for function keys.
  • one for implementing key repeats.

From the conversation it seems one is more problematic than the other.
By splitting in two, the less problematic one could be merged sooner, while the other one is being worked on.
Also, it makes reviewing more focused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants