当前位置:网站首页>Flutter Web 硬件键盘监听
Flutter Web 硬件键盘监听
2022-07-05 05:49:00 【bawomingtian123】
Flutter web在开发页面时使用到键盘监听,网上找了一圈都推荐使用RawKeyboardListener组件
但是在实际开发过程中发现该组件时常失灵导致无法监听到键盘输入。
现在给出解决方案,使用HardwareKeyboard对象。
使用方法获取HardwareKeyboard 单例,然后添加自己的回调方法
late HardwareKeyboard hardwareKeyboard;
@override
void initState() {
hardwareKeyboard = HardwareKeyboard.instance;
hardwareKeyboard.addHandler((event) {
print("event=${event.toStringShort()}");
return true;
});
super.initState();
}
这样监听每次都能监听到硬件键盘输入。
event=KeyDownEvent#b9cb2
event=KeyUpEvent#b073c
event=KeyDownEvent#8425d
event=KeyUpEvent#b8cec
event=KeyDownEvent#3c7a9
event=KeyUpEvent#c0b31
event=KeyDownEvent#9d155
event=KeyUpEvent#9b0ca
event=KeyDownEvent#5bd0b
event=KeyUpEvent#e8fdf
event=KeyDownEvent#78c1b
event=KeyUpEvent#0abb7
日志台输出如上,我们完全可以根据event对象判断出当前是什么按键输入,非常方便。
边栏推荐
- Pointnet++ learning
- Drawing dynamic 3D circle with pure C language
- Wazuh开源主机安全解决方案的简介与使用体验
- Bit mask of bit operation
- Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
- Configuration and startup of kubedm series-02-kubelet
- Daily question 1342 Number of operations to change the number to 0
- ALU逻辑运算单元
- [jailhouse article] look mum, no VM exits
- 2022 极术通讯-Arm 虚拟硬件加速物联网软件开发
猜你喜欢
用STM32点个灯
Chapter 6 data flow modeling - after class exercises
Sword finger offer 53 - ii Missing numbers from 0 to n-1
Implement an iterative stack
剑指 Offer 05. 替换空格
中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
sync. Interpretation of mutex source code
【Jailhouse 文章】Performance measurements for hypervisors on embedded ARM processors
1.15 - 输入输出系统
The connection and solution between the shortest Hamilton path and the traveling salesman problem
随机推荐
Little known skills of Task Manager
Scope of inline symbol
One question per day 2047 Number of valid words in the sentence
YOLOv5-Shufflenetv2
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
F - Two Exam(AtCoder Beginner Contest 238)
个人开发的渗透测试工具Satania v1.2更新
[practical skills] technical management of managers with non-technical background
剑指 Offer II 058:日程表
中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
全排列的代码 (递归写法)
每日一题-搜索二维矩阵ps二维数组的查找
【Jailhouse 文章】Jailhouse Hypervisor
Introduction and experience of wazuh open source host security solution
Sword finger offer 53 - I. find the number I in the sorted array
6. Logistic model
剑指 Offer 35.复杂链表的复制
Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
Transform optimization problems into decision-making problems
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module