使用按键模拟短信风格打字
谁能给我指明正确的方向,以便能够使用数字键盘上的按键来模拟短信风格的打字?
我可以让每个数字打印出一个字母,但不确定如何让我的程序将同一键上的多次按键视为同一“事件”(即,如果在一段时间内再次按下该键,则滚动浏览多个字母(例如)2 秒)。
我查找了多个按键,但总是想出组合键(ctrl、alt、delete 等)。
Can anyone point me in the right direction to be able to simulate sms style typing using keypress on the number pad?
I can get each number to print out a letter but am unsure of how to get my program to treat a number of keypresses on the same key as the same 'event' (i.e. scrolling through several letters if the key is pressed again within a period of (for example) 2 seconds).
I have looked up multiple keypresses but always come up with key combinations (ctrl, alt, delete etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个状态机并计算每个键的按下次数以确定字母。然后将这些字母(使用事件)传递给应用程序的其余部分。
诗。您是否注意到数字键盘上的数字顺序与电话上的顺序不同? (789 是键盘上的顶行和手机上的底行)
You need a state-machine and count the number of presses on each key to determine the letter. Then pass these letters on (using events) to the rest of your app.
Ps. did you notice that the numbers on a numeric keypad are in a different order than on a phone? (789 are the top row on a keyboard and the bottom row on a phone)
首先,您需要存储可用的组合:
然后我们制作组合的字典,映射到生成它们的正确键字符:
一些要跟踪的变量:
打印函数:
逻辑:
逻辑基本上检查以使得确保我们的键盘映射包含有问题的键码。如果我们没有跟踪任何内容,或者它与我们当前正在跟踪的内容不同,请使用该特定地图和第一个索引。
否则,如果是重复按键,则增加索引(如果经过末尾则循环回到开头)。
Firstly, you need to store the available combinations:
And then we make a dictionary of the combinations, mapped to the right key character that produces them:
Some variables to keep track:
A printing function:
And the logic:
The logic basically checks to make sure our keymap contains the keycode in question. If we're not tracking anything, or if it's different to the one we're currently tracking, use that particular map and the first index.
Otherwise, if it's a repeat key-press, increase the index (looping back to the beginning if we pass the end).