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

Control key support for software keyboards #141

Closed
LucasAschenbach opened this issue Oct 23, 2022 · 1 comment
Closed

Control key support for software keyboards #141

LucasAschenbach opened this issue Oct 23, 2022 · 1 comment
Assignees

Comments

@LucasAschenbach
Copy link
Contributor

LucasAschenbach commented Oct 23, 2022

I am currently using your package for a mobile app and am absolutely loving it! I would like to further work on supporting software keyboards to add even more functionality to this package. The main feature I would like to implement at the moment is support for control keys (control, alt, meta) as software buttons.

@xtyxtyx Considering that this feature will require a few fundamental changes in how key-inputs are handled and given that you are way more familiar with the overall project architecture, I wanted to discuss how to best implement this feature.

Proposal

My initial implementation approach for this would be to introduce a TerminalKeyboard class. An instance of this class would be passed to TerminalView and expose an API for manually entering keys into the terminal from within the app.

This would make for a very short and readable syntax when adding custom key input methods:

Button(
  onTap: () => terminalKeyboard.keyInput(TerminalKey.tab),
),
Button(
  onTap: () => terminalKeyboard.setAltPressed(!terminalKeyboard.isAltPressed),
),

Below the surface, this object would handle all logic related to text input from the software keyboard (i.e. TextInputClient) and store the state for whether ctrl, alt, meta are currently pressed on the virtual keyboard.

abstract class TerminalKeyboard {
  late InputClient _inputClient;
  Terminal? _terminal;

  // control keys
  bool _isAltPressed;
  bool get isAltPressed => _isAltPressed;
  set setAltPressed(bool value) => _isAltPressed = value;

  bool _isControlPressed;
  bool get isControlPressed => _isControlPressed;
  set setControlPressed(bool value) => _isControlPressed = value;

  bool _isMetaPressed;
  bool get isMetaPressed => _isMetaPressed;
  set setMetaPressed(bool value) => _isMetaPressed = value;

  // Enter key into terminal
  void keyInput(
    TerminalKey key, {
    bool isAltPressed = false,
    bool isControlPressed = false,
    bool isMetaPressed = false,
  });

  // creates input connection and attaches it to TextInput
  // (may only be called from within keyboard listener)
  void _attach();

  // closes input connection
  // (may only be called from within keyboard listener)
  void _detach();
}

This is just a rough sketch of course.

Please let me know your thoughts on this!

@xtyxtyx xtyxtyx self-assigned this Oct 29, 2022
xtyxtyx added a commit that referenced this issue Oct 30, 2022
@LucasAschenbach
Copy link
Contributor Author

Thanks for adding the example! Closing this.

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

No branches or pull requests

2 participants