因爲它只給出大寫字母,任何想法如何得到小寫? 如果用戶同時承認SHIFT + K或CAPSLOCK打開等,我想得到較低的情況。 是否有可能這樣或那樣?C++和GetAsyncKeyState()函數
感謝,
因爲它只給出大寫字母,任何想法如何得到小寫? 如果用戶同時承認SHIFT + K或CAPSLOCK打開等,我想得到較低的情況。 是否有可能這樣或那樣?C++和GetAsyncKeyState()函數
感謝,
正如你正確地指出,這是一個關鍵,而不是大寫或小寫。因此,對GetASyncKeyState(VK_SHIFT)的另一個調用可以幫助您確定shift鍵是否關閉,然後您將能夠適當地修改後續調用的結果。
假設「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;
正如我在前幾天提到的另一個問題中指出的,但爲了不同的目的,我也可以使用:http://msdn.microsoft.com/en-us/庫/ ms646322(VS.85).aspx如果是這樣,我不知道如何,不是一個Win32API專家。 – snoofkin 2010-11-16 11:45:33