C# Get Capslock Status works on Win7 but not Win10

  Kiến thức lập trình

Okay, so i have an GUI Application written in Matlab. And within Matlab i use a bit JAVA to simulate Keypresses to activate CAPSLOCK.
After this, i open my own written on-screen-keyboard, that i made in C# Winforms.
Now problem is, when i open the on-screen keyboard i check for capslock status like in


and then i update my onscreen keyboard to show big or small letters accordingly.
Now the problem is…On Notebook with Win7 it works,
BUT on the Touch-PC with Win10 it doesn’t work. It doesn’t show the correct Capslock
State. Is there a timed discrepancy between activating capslock and check if its activated?
Does Win10 has some other kind of functions to check for capslock?

I tried so many things, like checking in Application.Idle, doesn’t show the correct state.
I tried these global system hooks but they don’t even work at all. I can press anything i want
and i don’t get the hotkey message at all…

Any ideas what could be wrong?

I mean even if i write a little programm like,

                const int KEYEVENTF_EXTENDEDKEY = 0x1;
                const int KEYEVENTF_KEYUP = 0x2;
                keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
                keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
capsLockActivated = Control.IsKeyLocked(Keys.CapsLock);

It will show FALSE and thats even in Win7. So its probably timed discrepancy?
Before all that i had a licenced onscreen keyboard but i don’t want to pay everytime new licence so i tried writing my own keyboard. Everything works, just the capslock detection won’t really…

Oh, i already wrote that above. I tried Application.Idle, i tried keypress event, but that isn’t good because my onscreenkeyboard could be off focus. I tried global system hooks but that doesnt work at all, and i dont know why.