Anzeigen ob Tasten gedrückt sind



  • WebFritzi schrieb:

    GetKeyboardState(). Das ist das zweite mal, das ich das heute poste!

    Und wie benutzt ich das?



  • Schau in die MSDN. Da ist das ganz genau beschrieben.



  • Habe jetzt mal etwas danach gesucht. Jetzt sieht es so aus. Nur das es die falsche Shift Taste ist. Wieso will der nicht bei der oberen?

    if(GetKeyState(VK_SHIFT) == true)
      StatusBar->Panels->Items[5]->Text = "Gross";
      else
      StatusBar->Panels->Items[5]->Text = "";
    


  • meinst du VK_CAPITAL 😕



  • Ja, genau! So funktioniert das. Vielen Dank 👍



  • niemand schrieb:

    if(GetKeyState(VK_SHIFT) == true)
      StatusBar->Panels->Items[5]->Text = "Gross";
      else
      StatusBar->Panels->Items[5]->Text = "";
    

    Hast du keine platform SDK Doku?
    Ein Tipp: Du darfst nicht gegen true/false testen, da GetKeyState keinen BOOL zurückliefert.



  • Und wie mache ich das denn am besten??? 😕



  • Kann man in der [msdn]GetKeyState[/msdn] finden:

    MSDN schrieb:

    Return Value

    The return value specifies the status of the specified virtual key, as follows:

    If the high-order bit is 1, the key is down; otherwise, it is up.
    If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.



  • If the high-order bit is 1, the key is down; otherwise, it is up.
    If the low-order bit is 1, the key is toggled.

    Verstehe ich nicht. Der Return Value ist ein 16-Bit-Typ wie z.B. WORD. Wenn da jetzt "loworder byte" stehen würde, würde ich das ja einsehen, aber was ist ein loworder bit eines 16-Bit-Typs?



  • Wenn Du auf den Wert darufschaust, ist es das Bit ganz links (in diesem Fall Bit 15). Testen kann man das ganz einfach:

    #define BITSPERBYTE   8
    #define IS_MSB(x)     ((x) & (1 << ((sizeof((x)) * BITSPERBYTE) - 1)))
    
    if(IS_MSB(GetKeyState())
    {
    }
    else
    {
    }
    

    [edit]
    Das low-order bit ist das Bit ganz rechts, Bit 0. Das kannst Du auch ganz einfach testen:

    #define IS_LSB(x)     ((x) & 1)
    
    int a = 0;
    int b = 5;
    
    if(IS_LSB(a))
    {
    }
    
    if(IS_LSB(b))
    {
    }
    

    [/edit]


Anmelden zum Antworten