Skip to content

Command line keyboard events #37591

Open
Open
@idraper

Description

Dart SDK Version: Dart VM version: 2.4.0
OS: Windows 10 x64

I am working on a command line dart application and am looking for the ability to detect keyboard events. For example, if the user presses ctrl (or cmd), this would cause different behavior as the program executes tasks. I have found a few instances that seem to get close, but do not have the complete extendability I am looking for. Specifically:

I tried a very simple test, but similarly, it does not get very far:

import 'dart:io';
void main() {
  stdin.echoMode = false;
  stdin.lineMode = false;

  stdin.listen((data) {
    print (data);
  });
}

since it only prints out on pressing down (cannot detect holding a key) and does not recognize when the shift or ctrl key are pressed alone since they do not write alone.

Another thought that I have not tried yet was starting a separate process and try to detect keyboard input through a separate pipe, but this seems clunky and does not solve the root problem of lower-level access to keyboard interaction.

I am wondering if there is planned support for handling more advanced keyboard combinations (non-blocking) with special keys like ctrl and shift for command-line written dart applications. If there is not, whether any community libraries have been written. Lastly, if the answer is no to both questions, possible (preferably simple 😄) implementations. What would be of most importance is regarding holding ctrl or shift. Thanks!

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions