-
Notifications
You must be signed in to change notification settings - Fork 282
RawKeyboard events support #136
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
Comments
Some documentation about keyboard events:
|
#140 is ready to be merged, @erickzanardo, @luanpotter, you can test the pending feature using: Example Widget receiving Rawkeyevents (from FDE) (Clickable)// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
/// Keyboard test page for the example application.
class KeyboardTestPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _KeyboardTestPageState();
}
}
class _KeyboardTestPageState extends State<KeyboardTestPage> {
final List<String> _messages = [];
final FocusNode _focusNode = FocusNode();
final ScrollController _scrollController = new ScrollController();
@override
void didChangeDependencies() {
super.didChangeDependencies();
FocusScope.of(context).requestFocus(_focusNode);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: new Text('Keyboard events test'),
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
})),
body: new RawKeyboardListener(
focusNode: _focusNode,
onKey: onKeyEvent,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: SingleChildScrollView(
controller: _scrollController,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _messages.map((m) => new Text(m)).toList())),
),
),
);
}
void onKeyEvent(RawKeyEvent event) {
bool isKeyDown;
switch (event.runtimeType) {
case RawKeyDownEvent:
isKeyDown = true;
break;
case RawKeyUpEvent:
isKeyDown = false;
break;
default:
throw new Exception('Unexpected runtimeType of RawKeyEvent');
}
int keyCode;
switch (event.data.runtimeType) {
case RawKeyEventDataLinux:
final RawKeyEventDataLinux data = event.data;
keyCode = data.keyCode;
break;
default:
throw new Exception('Unsupported platform ${event.data.runtimeType}');
}
_addMessage('${isKeyDown ? 'KeyDown' : 'KeyUp'}: $keyCode\n- Modifiers: ${event.data.modifiersPressed}\n- KeyLabel: ${event.data.logicalKey.keyLabel}\n- debugName: ${event.data.logicalKey.debugName}');
}
void _addMessage(String message) {
setState(() {
_messages.add(message);
});
SchedulerBinding.instance.addPostFrameCallback((_) {
_scrollController.jumpTo(
_scrollController.position.maxScrollExtent,
);
});
}
}
|
That is some awesome news! I will be testing this tomorrow and report here. Thanks a lot |
I will review the PR soon:tm:! |
@erickzanardo make sure to also checkout: #144 ;) |
@Drakirus I tested and it worked great! I have already added an example on Flame's repository if you want to check out: flame-engine/flame#92 Just a couple of comments, I tested on MacOs, and I have received instances of Also, I noticed a lot of these messages on the console while I kept the key pressed: About #144 I took a lot on the PR but did not figured it out how to activate de fullscreen. Thanks a lot for implementing this, and great work on this library. |
Using go-flutter, you will receive To start an app in fullscreen, add to the options list: Make sure the app can close itself from full screen, or you'll be stuck in fullscreen ;) |
@erickzanardo Tanks for your feedback! The The flutter framework supports only |
Awesome, thanks for the clarifications @Drakirus and @GeertJohan! I just tested the fullscreen feature and it worked pretty well. Awesome work! |
Thanks @erickzanardo @Drakirus Perhaps we can 'silence' the Unknown event type when it is glfw.Repeat? |
I was about to submit a PR on flutter/flutter that adds a new
Adding support for For now, what I think we should do is to match the Android and MacOS implementation where multiples successive @GeertJohan do you have any objections? (we'll keep the comment saying If interested: Source of the the patch adding `RawKeyRepeatEvent` (Clickable)From 2fb1a185761dc85c79aa2a75815f23cc9cc194d3 Mon Sep 17 00:00:00 2001
From: Drakirus <[email protected]>
Date: Wed, 22 May 2019 17:37:02 +0200
Subject: [PATCH] Add RawKeyRepeatEvent
---
.../lib/src/services/raw_keyboard.dart | 25 ++++++++++++++++---
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/packages/flutter/lib/src/services/raw_keyboard.dart b/packages/flutter/lib/src/services/raw_keyboard.dart
index cf449ab27..b785a78b5 100644
--- a/packages/flutter/lib/src/services/raw_keyboard.dart
+++ b/packages/flutter/lib/src/services/raw_keyboard.dart
@@ -105,8 +105,8 @@ enum ModifierKey {
///
/// * [RawKeyEventDataAndroid], a specialization for Android.
/// * [RawKeyEventDataFuchsia], a specialization for Fuchsia.
-/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes that hold the
-/// reference to [RawKeyEventData] subclasses.
+/// * [RawKeyDownEvent], [RawKeyUpEvent] and [RawKeyRepeatEvent], the classes
+/// that hold the reference to [RawKeyEventData] subclasses.
/// * [RawKeyboard], which uses these interfaces to expose key data.
@immutable
abstract class RawKeyEventData {
@@ -230,6 +230,8 @@ abstract class RawKeyEventData {
/// pressing a key.
/// * [RawKeyUpEvent], a specialization for events representing the user
/// releasing a key.
+/// * [RawKeyRepeatEvent], a specialization for events representing the user
+/// holding down a key.
/// * [RawKeyboard], which uses this interface to expose key data.
/// * [RawKeyboardListener], a widget that listens for raw key events.
@immutable
@@ -294,6 +296,8 @@ abstract class RawKeyEvent {
return RawKeyDownEvent(data: data, character: message['character']);
case 'keyup':
return RawKeyUpEvent(data: data);
+ case 'keyrepeat':
+ return RawKeyRepeatEvent(data: data);
default:
throw FlutterError('Unknown key event type: $type');
}
@@ -434,6 +438,19 @@ class RawKeyUpEvent extends RawKeyEvent {
}) : super(data: data, character: character);
}
+/// The user has held down a key on the keyboard until it repeated.
+///
+/// See also:
+///
+/// * [RawKeyboard], which uses this interface to expose key data.
+class RawKeyRepeatEvent extends RawKeyEvent {
+ /// Creates a key event that represents the user holding down a key.
+ const RawKeyRepeatEvent({
+ @required RawKeyEventData data,
+ String character,
+ }) : super(data: data, character: character);
+}
+
/// An interface for listening to raw key events.
///
/// Raw key events pass through as much information as possible from the
@@ -446,8 +463,8 @@ class RawKeyUpEvent extends RawKeyEvent {
///
/// See also:
///
-/// * [RawKeyDownEvent] and [RawKeyUpEvent], the classes used to describe
-/// specific raw key events.
+/// * [RawKeyDownEvent], [RawKeyUpEvent] and [RawKeyRepeatEvent], the classes
+/// used to describe specific raw key events.
/// * [RawKeyboardListener], a widget that listens for raw key events.
/// * [SystemChannels.keyEvent], the low-level channel used for receiving
/// events from the system.
--
2.21.0 |
Sounds good @drakirus |
Hello,
This may be a little out of scope of the project, but would be cool if there were support to RawKeyboard Events on this project.
I am a collaborator at a flutter game engine (https://github.com/luanpotter/flame), and with this kind of support, we could bring flutter games to desktop.
Thanks
The text was updated successfully, but these errors were encountered: