我有一些不典型的问题。我向用户提供 sendText() 函数。他可以输入例如
sendText( "mytext{newline}text{up}" )
{text} 是允许用户发送的特殊密钥。有很多特殊的键可用。
所以我的第一步是获取 {} 括号之间的字符串并创建:
if( _specialKey == "newline" ) {
// action for VK_RETURN
} else if( _specialKey == "up" ) {
// action for VK_UP
} else .....
例子:
if( specialKey == "n" ) {
// enter click
unsigned short key = VK_RETURN;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "n+" ) {
// enter down
inputs.push_back( keyDown( VK_RETURN ) );
return 2;
} else if( specialKey == "n-" ) {
// enter up
inputs.push_back( keyUp( VK_RETURN ) );
return 2;
} else if( specialKey == "t" ) {
// tabulator click
unsigned short key = VK_TAB;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "t+" ) {
// tabulator down
inputs.push_back( keyDown( VK_TAB ) );
return 2;
} else if( specialKey == "t-" ) {
// tabulator up
inputs.push_back( keyUp( VK_TAB ) );
return 2;
} else if( specialKey == "caps" ) {
// caps lock click
unsigned short key = VK_CAPITAL;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "caps+" ) {
// caps lock down
inputs.push_back( keyDown( VK_CAPITAL ) );
return 2;
} else if( specialKey == "caps-" ) {
// caps lock up
inputs.push_back( keyUp( VK_CAPITAL ) );
return 2;
} else if( specialKey == "ralt" ) {
// right alt click
unsigned short key = VK_RMENU;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "ralt+" ) {
// right alt down
inputs.push_back( keyDown( VK_RMENU ) );
return 2;
} else if( specialKey == "ralt-" ) {
// right alt up
inputs.push_back( keyUp( VK_RMENU ) );
return 2;
} else if( specialKey == "lalt" ) {
// right alt click
unsigned short key = VK_LMENU;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "lalt+" ) {
// right alt down
inputs.push_back( keyDown( VK_LMENU ) );
return 2;
} else if( specialKey == "lalt-" ) {
// right alt up
inputs.push_back( keyUp( VK_LMENU ) );
return 2;
} else if( specialKey == "rctrl" ) {
// right alt click
unsigned short key = VK_RCONTROL;
inputs.push_back( keyDown( key ) );
inputs.push_back( keyUp( key ) );
return 2;
} else if( specialKey == "rctrl+" ) {
// right alt down
inputs.push_back( keyDown( VK_RCONTROL ) );
return 2;
} else if( specialKey == "rctrl-" ) {
// right alt up
inputs.push_back( keyUp( VK_RCONTROL ) );
return 2;
} else if( specialKey == "lctrl" ) {
但编译器说:
fatal error C1061: compiler limit : blocks nested too deeply
我解决它的第一个想法是定义一个映射,该映射将存储映射到某个整数的所有特殊键(作为字符串)。然后我可以这样做:
switch( map[key] ) {
case 0:
...
}
但我不确定编译器是否也会抱怨它。有很多东西要改变,所以我不想因为没有结果而改变它。
或者你还有其他更好的想法吗?
谢谢。