2010-11-16 54 views
1

因为它只给出大写字母,任何想法如何得到小写? 如果用户同时承认SHIFT + K或CAPSLOCK打开等,我想得到较低的情况。 是否有可能这样或那样?C++和GetAsyncKeyState()函数

感谢,

回答

2

正如你正确地指出,这是一个关键,而不是大写或小写。因此,对GetASyncKeyState(VK_SHIFT)的另一个调用可以帮助您确定shift键是否关闭,然后您将能够适当地修改后续调用的结果。

+0

正如我在前几天提到的另一个问题中指出的,但为了不同的目的,我也可以使用:http://msdn.microsoft.com/en-us/库/ ms646322(VS.85).aspx如果是这样,我不知道如何,不是一个Win32API专家。 – snoofkin 2010-11-16 11:45:33

3

假设“c”是您放入GetAsyncKeyState()的变量。

您可以使用以下方法检测您是否应该打印大写字母或小写字母。

string out = ""; 

bool isCapsLock() { // Check if CapsLock is toggled 
    if ((GetKeyState(VK_CAPITAL) & 0x0001) != 0) // If the low-order bit is 1, the key is toggled 
     return true; 
    else 
     return false; 
} 

bool isShift() { // Check if shift is pressed 
    if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) // If the high-order bit is 1, the key is down; otherwise, it is up. 
     return true; 
    else 
     return false; 
} 

if (c >= 65 && c <= 90) { // A-Z 
    if (!(isShift()^isCapsLock())) { // Check if the letter should be lower case 
     c += 32; // in ascii table A=65, a=97. 97-65 = 32 
} 
out = c;