C++绑定键盘按键:迭代所有虚拟键?
我希望能够为我的应用程序加载自定义按键绑定。配置文件通常包含键列表和关联的函数名称。
当我加载此文件时,是否有一种方法可以迭代配置文件中以以下形式列出的所有可能的虚拟键:
for(int i = key0; i < keymax; i = i+key){
char key = itoa(i);
if(cfgfile.getfunction(key,function)){
_keyBinds[key] = function;
}
}
或者我是否需要手动检查其中的每一个?
I'd like to be able to load custom key binds for my application. A configuration file would typically contain a list of keys and associated function names.
When I load this file, is there a way to iterate over all the possible virtual keys that would be listed inside the configuration file in the form:
for(int i = key0; i < keymax; i = i+key){
char key = itoa(i);
if(cfgfile.getfunction(key,function)){
_keyBinds[key] = function;
}
}
Or do I need to manually check for every one of them ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我最终创建键盘按键映射的方法。它涵盖了几乎所有可能性:不可映射键存储为十六进制字符串,不将自身表示为单个字符的可映射键需要手动添加。也许这对将来的某人有用。
This is the way I finally proceeded to create a map of the keyboard keys. It covers almost all possibilities: non-mappable keys are stored as a hex string, mappable keys which do not represent themselves as a single caracter need to be added manually. Maybe this can be usefull for someone in the future.
在加载文件内容的例程中,您需要将数据存储在 < code>map 以键码作为键,以函数名称作为值。那么,只需迭代映射中的条目,而不是迭代所有可能的键码。
In your routine that loads the contents of the file, you'll want to store the data in a
map
with the keycodes as the keys and function names as the values. Instead of iterating over all possible keycodes, then, just iterate over the entries in the map.