Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

key - C++ and GetAsyncKeyState() function

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...