【问题标题】:C++ and GetAsyncKeyState() functionC++ 和 GetAsyncKeyState() 函数
【发布时间】:2010-11-16 10:32:15
【问题描述】:

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

谢谢,

【问题讨论】:

    标签: c++ key winapi


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多