-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useKeyPress是否可以支持重复按一个按键N次然后再触发回调逻辑 #2286
Comments
目前不支持这种需求。可以自己记录触发的次数,然后根据次数再执行某些逻辑 |
我可以提交PR改造下ahooks提供这种场景么?类似我上面的例子。 |
现有通过计数肯定是能实现的,只是想便捷点,只想写快捷键 + 回调逻辑,相当于把计数逻辑放到ahooks里了,不知是否合理。 |
可以说说你的思路,准备加怎样的参数来支持这个能力,像你举例的这种用法是不太行的,如果重复按三次要这样写: useKeyPress(['s', 's', 's'], () => {
setState(1);
}); 那重复N多次,理论上要写N次,虽然可以通过一些语法简化( 如果有更好的思路可以分享下,一起评估下,可以的话来个 PR 另外,useKeyPress 里支持的快捷键格式有:字符串 |
嗯,我明白,我想想。 |
大佬你好,增加一种新的格式来兼容是否可行呢 useKeyPress([{'shift.c':2},{'a':3},{'1':4},{2:3}]) |
看起来不错。 可以在此基础上,扩展一些其他思路:
useKeyPress({
'shift.c': 2,
a: 3,
'1': 4,
2: 3,
});
useKeyPress(['ctrl.c', { 'shift.c': 2 }, 'shift']); |
这个连击的有效时间段是否需要考虑可以使用者自定义呢, 比如初始值2000ms(默认情况下在2000ms内,连按Q键10次就会触发回调), useKeyPress([ { 2: 3 } ], fn, { timeInterval: 2000 } ); 或者,让使用者可以定义每个连击按键的有效时间区间 useKeyPress( [ {'a': 2 }, {"shift.c": { counter: 2 , timeInterval: 5000 } ] );
|
如果加上连击能力,确实要考虑“有效时间段”、“连击最小间隔”等这些情况~ |
比如
连续按下三次“s”按键再执行setState(1)
The text was updated successfully, but these errors were encountered: