C++和 GetAsyncKeyState() 函数

发布于 2024-10-02 21:14:36 字数 97 浏览 1 评论 0原文

由于它只给出大写字母,所以知道如何获得小写字母吗? 如果用户同时按下 SHIFT+K 或 CAPSLOCK 等,我想得到小写。 以这种方式或其他方式可能吗?

谢谢,

As it gives only Upper case letters, any idea how to get lower case??
If the user simultaneously pessed SHIFT+K or CAPSLOCK is on,etc, I want to get lower cases..
is it possible in this way or another??

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不离久伴 2024-10-09 21:14:36

假设“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;

Suppose "c" is the variable you put into GetAsyncKeyState().

You may use the following method to detect whether you should print upper case letter or lower case letter.

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;
九局 2024-10-09 21:14:36

正如您正确指出的那样,它代表一个键,而不是大写或小写。因此,也许再次调用 ::GetASyncKeyState(VK_SHIFT) 可以帮助您确定 Shift 键是否按下,然后您将能够适当地修改后续调用的结果。

As you rightly point out, it represents a key and not upper or lower-case. Therefore, perhaps another call to ::GetASyncKeyState(VK_SHIFT) can help you to determine if the shift-key is down and then you will be able to modify the result of your subsequent call appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文