We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
我可能会使用命令模式之类的东西。创建一个哈希表,其中键是按下的键,值是要执行的操作的函数(或具有函数的对象)。
虽然可能有一种更快的方法可以在 CPU 时间内完成此操作,但这似乎是最干净、最可维护的方法,并且对于单用户应用程序来说它足够快,因此干净的代码应该非常重要。
I might use something like the Command Pattern. Create a hashtable, where the key is the key pressed, and the value is a function (or object with a function) that's the action to be executed.
While there's probably a much faster way to do this in CPU-time, that seems the cleanest and most maintainable way, and it's fast enough for a single-user application that clean code should be pretty important.