wanna implement keyboard shortcuts into web app, found this example but it doesn't work as expected.
Would like action to occur every time I hold down alt and then press key A, though action occurs only when I press key alt and key A at the same time
thank
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyIntent extends Intent {}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
int integer = 0;
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Shortcuts(
shortcuts: {
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.keyA):
MyIntent(),
},
child: Actions(
actions: {
MyIntent: CallbackAction(onInvoke: (i) {
print('rocks!!!' '$integer');
integer++;
return null;
}),
},
child: Focus(
autofocus: true,
child: SizedBox(
height: 200,
width: 500,
child: Column(
children: <Widget>[
const Text('List of Homework'),
],
),
),
),
),
),
);
}
}
You can do that in the following way: SingleActivator(LogicalKeyboardKey.keyA, alt: true)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.