You are using a version without Ads of this website. Please, consider donating:

### Virtual Key

.....................................................................................................................
Hey guys hi good morning now today I've finished the function Virtual Key to char data conversion.
In short, I need your suggestions to improve this function.

Now here's the code VkKey -> unsigned char().
This function translates a virtual key (from keyboard) to a regular char value. Eg -> VK_A will generate "a" (Capslock is off)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081`` ``````inline unsigned char GetNumberSymbol(unsigned char num) { switch(num){ case 0 : return ')'; break; case 1 : return '!'; break; case 2 : return '@'; break; case 3 : return '#'; break; case 4 : return '\$'; break; case 5 : return '%'; break; case 6 : return '^'; break; case 7 : return '&'; break; case 8 : return '*'; break; case 9 : return '('; break; } return '0' + num; } unsigned char vkToChar(unsigned char vKey, bool bCapsLock = false) { ////////////////////////////////////////////////////////////////////////////////////// //Numbers, letters if(vKey < 0x30)return 0; if(vKey > 0x40 && vKey <= 0x5A) { if(!bCapsLock) return 'a' + vKey - 0x41; return 'a' + vKey - 0x41 - 32; } if(vKey <= 0x39) { if(!bCapsLock)return vKey; return GetNumberSymbol(vKey - '0');} if(vKey > 0x60 && vKey <= 0x69) { if(!bCapsLock) return '0' + vKey - 0x60; return GetNumberSymbol(vKey - 0x60); } ////////////////////////////////////////////////////////////////////////////////////// //Symbols if(vKey >= 186){ vKey-= 186; if(vKey <= 6) { if(!bCapsLock) switch(vKey){ case 0 : return ';'; break; case 1 : return '='; break; case 2 : return ','; break; case 3 : return '-'; break; case 4 : return '.'; break; case 5 : return '/'; break; case 6 : return '`'; break; } switch(vKey){ case 0 : return ':'; break; case 1 : return '+'; break; case 2 : return '<'; break; case 3 : return '_'; break; case 4 : return '>'; break; case 5 : return '?'; break; case 6 : return '~'; break; } } ////////////////////////////////////////////////////////////////////////////////////// //Other symbols if(vKey > 32 && vKey < 37){ if(!bCapsLock){ if(vKey == 33)return '[';else if(vKey == 35)return ']';else if(vKey == 36)return 39;} else{ if(vKey == 33)return '{';else if(vKey == 35)return '}';else if(vKey == 36)return '"';} }} ////////////////////////////////////////////////////////////////////////////////////// return 0; }``````

Any suggestion?
(Any help would be greatly appreciated.)
Last edited on
closed account (DSLq5Di1)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646306
@Jackson Marie - I suggest that you write functions that only have one exit point. Writing functions that have exit points i.e. return ... ; all over the place is a bad habit and isn't easy to debug, as is having seperate lines of code on the same line.
Topic archived. No new replies allowed.