|
|
|
|
@@ -46,75 +46,11 @@ abstract class KeyboardKey with Diagnosticable {
|
|
|
|
|
/// look at the physical key to make sure that regardless of the character the
|
|
|
|
|
/// key produces, you got the key that is in that location on the keyboard.
|
|
|
|
|
///
|
|
|
|
|
/// {@tool dartpad --template=stateful_widget_scaffold}
|
|
|
|
|
/// {@tool dartpad}
|
|
|
|
|
/// This example shows how to detect if the user has selected the logical "Q"
|
|
|
|
|
/// key.
|
|
|
|
|
///
|
|
|
|
|
/// ```dart imports
|
|
|
|
|
/// import 'package:flutter/foundation.dart';
|
|
|
|
|
/// import 'package:flutter/services.dart';
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// // The node used to request the keyboard focus.
|
|
|
|
|
/// final FocusNode _focusNode = FocusNode();
|
|
|
|
|
/// // The message to display.
|
|
|
|
|
/// String? _message;
|
|
|
|
|
///
|
|
|
|
|
/// // Focus nodes need to be disposed.
|
|
|
|
|
/// @override
|
|
|
|
|
/// void dispose() {
|
|
|
|
|
/// _focusNode.dispose();
|
|
|
|
|
/// super.dispose();
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// // Handles the key events from the RawKeyboardListener and update the
|
|
|
|
|
/// // _message.
|
|
|
|
|
/// void _handleKeyEvent(RawKeyEvent event) {
|
|
|
|
|
/// setState(() {
|
|
|
|
|
/// if (event.logicalKey == LogicalKeyboardKey.keyQ) {
|
|
|
|
|
/// _message = 'Pressed the "Q" key!';
|
|
|
|
|
/// } else {
|
|
|
|
|
/// if (kReleaseMode) {
|
|
|
|
|
/// _message = 'Not a Q: Pressed 0x${event.logicalKey.keyId.toRadixString(16)}';
|
|
|
|
|
/// } else {
|
|
|
|
|
/// // The debugName will only print useful information in debug mode.
|
|
|
|
|
/// _message = 'Not a Q: Pressed ${event.logicalKey.debugName}';
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// });
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// @override
|
|
|
|
|
/// Widget build(BuildContext context) {
|
|
|
|
|
/// final TextTheme textTheme = Theme.of(context).textTheme;
|
|
|
|
|
/// return Container(
|
|
|
|
|
/// color: Colors.white,
|
|
|
|
|
/// alignment: Alignment.center,
|
|
|
|
|
/// child: DefaultTextStyle(
|
|
|
|
|
/// style: textTheme.headline4!,
|
|
|
|
|
/// child: RawKeyboardListener(
|
|
|
|
|
/// focusNode: _focusNode,
|
|
|
|
|
/// onKey: _handleKeyEvent,
|
|
|
|
|
/// child: AnimatedBuilder(
|
|
|
|
|
/// animation: _focusNode,
|
|
|
|
|
/// builder: (BuildContext context, Widget? child) {
|
|
|
|
|
/// if (!_focusNode.hasFocus) {
|
|
|
|
|
/// return GestureDetector(
|
|
|
|
|
/// onTap: () {
|
|
|
|
|
/// FocusScope.of(context).requestFocus(_focusNode);
|
|
|
|
|
/// },
|
|
|
|
|
/// child: const Text('Tap to focus'),
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// return Text(_message ?? 'Press a key');
|
|
|
|
|
/// },
|
|
|
|
|
/// ),
|
|
|
|
|
/// ),
|
|
|
|
|
/// ),
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
/// ** See code in examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart **
|
|
|
|
|
/// {@end-tool}
|
|
|
|
|
/// See also:
|
|
|
|
|
///
|
|
|
|
|
@@ -318,9 +254,9 @@ class LogicalKeyboardKey extends KeyboardKey {
|
|
|
|
|
@override
|
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
|
properties.add(StringProperty('keyId', '0x${keyId.toRadixString(16).padLeft(8, '0')}', showName: true));
|
|
|
|
|
properties.add(StringProperty('keyLabel', keyLabel, showName: true));
|
|
|
|
|
properties.add(StringProperty('debugName', debugName, showName: true, defaultValue: null));
|
|
|
|
|
properties.add(StringProperty('keyId', '0x${keyId.toRadixString(16).padLeft(8, '0')}'));
|
|
|
|
|
properties.add(StringProperty('keyLabel', keyLabel));
|
|
|
|
|
properties.add(StringProperty('debugName', debugName, defaultValue: null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@@MASK_CONSTANTS@@@
|
|
|
|
|
@@ -365,69 +301,11 @@ class LogicalKeyboardKey extends KeyboardKey {
|
|
|
|
|
/// looking for "the key next to the TAB key", since on a French keyboard,
|
|
|
|
|
/// the key next to the TAB key has an "A" on it.
|
|
|
|
|
///
|
|
|
|
|
/// {@tool dartpad --template=stateful_widget_scaffold}
|
|
|
|
|
/// {@tool dartpad}
|
|
|
|
|
/// This example shows how to detect if the user has selected the physical key
|
|
|
|
|
/// to the right of the CAPS LOCK key.
|
|
|
|
|
///
|
|
|
|
|
/// ```dart imports
|
|
|
|
|
/// import 'package:flutter/services.dart';
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// // The node used to request the keyboard focus.
|
|
|
|
|
/// final FocusNode _focusNode = FocusNode();
|
|
|
|
|
/// // The message to display.
|
|
|
|
|
/// String? _message;
|
|
|
|
|
///
|
|
|
|
|
/// // Focus nodes need to be disposed.
|
|
|
|
|
/// @override
|
|
|
|
|
/// void dispose() {
|
|
|
|
|
/// _focusNode.dispose();
|
|
|
|
|
/// super.dispose();
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// // Handles the key events from the RawKeyboardListener and update the
|
|
|
|
|
/// // _message.
|
|
|
|
|
/// void _handleKeyEvent(RawKeyEvent event) {
|
|
|
|
|
/// setState(() {
|
|
|
|
|
/// if (event.physicalKey == PhysicalKeyboardKey.keyA) {
|
|
|
|
|
/// _message = 'Pressed the key next to CAPS LOCK!';
|
|
|
|
|
/// } else {
|
|
|
|
|
/// _message = 'Wrong key.';
|
|
|
|
|
/// }
|
|
|
|
|
/// });
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// @override
|
|
|
|
|
/// Widget build(BuildContext context) {
|
|
|
|
|
/// final TextTheme textTheme = Theme.of(context).textTheme;
|
|
|
|
|
/// return Container(
|
|
|
|
|
/// color: Colors.white,
|
|
|
|
|
/// alignment: Alignment.center,
|
|
|
|
|
/// child: DefaultTextStyle(
|
|
|
|
|
/// style: textTheme.headline4!,
|
|
|
|
|
/// child: RawKeyboardListener(
|
|
|
|
|
/// focusNode: _focusNode,
|
|
|
|
|
/// onKey: _handleKeyEvent,
|
|
|
|
|
/// child: AnimatedBuilder(
|
|
|
|
|
/// animation: _focusNode,
|
|
|
|
|
/// builder: (BuildContext context, Widget? child) {
|
|
|
|
|
/// if (!_focusNode.hasFocus) {
|
|
|
|
|
/// return GestureDetector(
|
|
|
|
|
/// onTap: () {
|
|
|
|
|
/// FocusScope.of(context).requestFocus(_focusNode);
|
|
|
|
|
/// },
|
|
|
|
|
/// child: const Text('Tap to focus'),
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// return Text(_message ?? 'Press a key');
|
|
|
|
|
/// },
|
|
|
|
|
/// ),
|
|
|
|
|
/// ),
|
|
|
|
|
/// ),
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
/// ** See code in examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart **
|
|
|
|
|
/// {@end-tool}
|
|
|
|
|
///
|
|
|
|
|
/// See also:
|
|
|
|
|
@@ -483,8 +361,8 @@ class PhysicalKeyboardKey extends KeyboardKey {
|
|
|
|
|
@override
|
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
|
properties.add(StringProperty('usbHidUsage', '0x${usbHidUsage.toRadixString(16).padLeft(8, '0')}', showName: true));
|
|
|
|
|
properties.add(StringProperty('debugName', debugName, showName: true, defaultValue: null));
|
|
|
|
|
properties.add(StringProperty('usbHidUsage', '0x${usbHidUsage.toRadixString(16).padLeft(8, '0')}'));
|
|
|
|
|
properties.add(StringProperty('debugName', debugName, defaultValue: null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Key constants for all keyboard keys in the USB HID specification at the
|
|
|
|
|
|