因为它只给出大写字母,所以知道如何获得小写字母吗?如果用户同时按下 SHIFT+K 或 CAPSLOCK 等,我想得到小写..是否有可能以这种方式或其他方式?
谢谢,
假设“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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5647 次 |
| 最近记录: |