当前位置:网站首页>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对象判断出当前是什么按键输入,非常方便。
边栏推荐
- Configuration and startup of kubedm series-02-kubelet
- Personal developed penetration testing tool Satania v1.2 update
- Convolution neural network -- convolution layer
- Some common problems in the assessment of network engineers: WLAN, BGP, switch
- 剑指 Offer 58 - II. 左旋转字符串
- Wazuh開源主機安全解决方案的簡介與使用體驗
- 个人开发的渗透测试工具Satania v1.2更新
- Daily question 1688 Number of matches in the competition
- How to adjust bugs in general projects ----- take you through the whole process by hand
- shared_ Repeated release heap object of PTR hidden danger
猜你喜欢

Introduction and experience of wazuh open source host security solution
![[cloud native] record of feign custom configuration of microservices](/img/39/05cf7673155954c90e75a8a2eecd96.jpg)
[cloud native] record of feign custom configuration of microservices

Implement an iterative stack

SAP method of modifying system table data

中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章

浅谈JVM(面试常考)

A misunderstanding about the console window

sync. Interpretation of mutex source code

AtCoder Grand Contest 013 E - Placing Squares
![[jailhouse article] look mum, no VM exits](/img/fe/87e0851d243f14dff96ef1bc350e50.png)
[jailhouse article] look mum, no VM exits
随机推荐
7. Processing the input of multidimensional features
kubeadm系列-00-overview
CF1634E Fair Share
Sword finger offer 58 - ii Rotate string left
Sword finger offer 53 - ii Missing numbers from 0 to n-1
1.14 - 流水线
Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
剑指 Offer 05. 替换空格
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
【Jailhouse 文章】Jailhouse Hypervisor
One question per day 2047 Number of valid words in the sentence
YOLOv5-Shufflenetv2
sync. Interpretation of mutex source code
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
游戏商城毕业设计
2022 pole technology communication arm virtual hardware accelerates the development of Internet of things software
剑指 Offer 58 - II. 左旋转字符串
Some common problems in the assessment of network engineers: WLAN, BGP, switch
2020ccpc Qinhuangdao J - Kingdom's power
2022年贵州省职业院校技能大赛中职组网络安全赛项规程