lower key being pressed?

Hi guys I noticed when I type a on the console it keeps on printing an upper case 'A',this will be printed even if my caps lock is off,I wonder why?

as the ascii values are clearly different

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
#include <windows.h>

using namespace std;

int main()
{

    char i;

    while(true){


        for(int i = 8; i < 255; i++){

            if(GetAsyncKeyState(i) == -32767){

                 if(i == 65){

                    char c = (char) i;
                    cout << c << endl;

                 }
            }
        }
    }
}
also I am trying to detect if caps lock key was pressed

still need to figure out the logic


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    char i;

    bool caps = false;

    while(true){

        for(int i = 8; i < 255; i++){


            if(GetAsyncKeyState(i) == -32767){

                if(GetAsyncKeyState(i) == VK_CAPITAL){

                  caps = true;
                 }

                 if(i == 65 && caps){

                    char c = (char) i;
                    cout << c << endl;
                    caps = false;
                 }

                 if(i == 65 && !caps){

                    char c = (char) i;
                    c = c + 32;
                    cout << c << endl;

                 }
            }
        }
    }
}
Last edited on
Ok found a way to check if caps lock is on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    char i;

    bool caps = false;

    while(true){

        for(int i = 8; i < 255; i++){

        
        // program tests to see if the a key is pressed also checks to see if it is a capital or lower case pressed
        // if((GetKeyState(VK_CAPITAL) & 0x0001)!=0 if not = 0 that means caps is on and if 0 means it is off 

            if(GetAsyncKeyState(i) == -32767){

                 if((GetKeyState(VK_CAPITAL) & 0x0001)!=0){

                    caps = true;
                 }
                 if((GetKeyState(VK_CAPITAL) & 0x0001)==0){

                    caps = false;
                 }
                 if(i == 65 && !caps){

                    char c = (char) i;
                    c = c + 32;
                    cout << c << endl;

                 }

                 if(i == 65 && caps){

                    char c = (char) i;
                    cout << c << endl;
                 }

            }
        }
    }
}




GetKeyState(VK_CAPITAL) & 0x0001)==0

I'm wondering why we use a bitwise & rather than a logical & if I was to take an educated guess I would we are checking to see if VK_CAPITAL's last bit is set to 0 then caps lock is off?

thanks
Topic archived. No new replies allowed.