CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2014
    Posts
    61

    GetKeyState(VK_CAPITAL) and GetKeyState(VK_SHIFT) together pressed to lowercase

    Hello guys!

    I'm trying make a code for convert recorded key to lowercase when Caps Lock key and Shift key are pressed, but is don't work, always stay uppercase. Can someone help me please?

    Here is my attempt =>

    Code:
    BOOL isShiftCaps()
    {
    
    if ((GetKeyState(VK_CAPITAL) & 0x0001)==1) {
    if ((GetKeyState(VK_SHIFT) & 0x8000)<0);
         return 1;
         } else { return 0; }
         
         
    }
    
    
    // trying write lowercase characteres to file
    
    if (isShiftCaps() == 1) {
                    write(Key);
                 }
    Thank in advance.
    Last edited by FL4SHC0D3R; July 19th, 2014 at 01:36 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: GetKeyState(VK_CAPITAL) and GetKeyState(VK_SHIFT) together pressed to lowercase

    What is Key?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: GetKeyState(VK_CAPITAL) and GetKeyState(VK_SHIFT) together pressed to lowercase

    Quote Originally Posted by FL4SHC0D3R View Post
    Hello guys!

    I'm trying make a code for convert recorded key to lowercase when Caps Lock key and Shift key are pressed, but is don't work, always stay uppercase. Can someone help me please?

    Here is my attempt =>

    Code:
    BOOL isShiftCaps()
    {
    
    if ((GetKeyState(VK_CAPITAL) & 0x0001)==1) {
    if ((GetKeyState(VK_SHIFT) & 0x8000)<0);
         return 1;
         } else { return 0; }
         
         
    }
    
    
    // trying write lowercase characteres to file
    
    if (isShiftCaps() == 1) {
                    write(Key);
                 }
    Thank in advance.
    Code:
    if ((GetKeyState(VK_SHIFT) & 0x8000)<0);
    I think you have an extra ; here.

    Also as the function is returning a type BOOL why not use TRUE and FALSE instead of 1 and 0?

    Your code can probably be shortened to
    Code:
    BOOL isShiftCaps()
    {
        return ((GetKeyState(VK_CAPITAL) & 0x0001) == 1) && ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000);
    }
    Last edited by 2kaud; July 19th, 2014 at 11:33 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Apr 2014
    Posts
    61

    Re: GetKeyState(VK_CAPITAL) and GetKeyState(VK_SHIFT) together pressed to lowercase

    Quote Originally Posted by 2kaud View Post
    Code:
    if ((GetKeyState(VK_SHIFT) & 0x8000)<0);
    I think you have an extra ; here.

    Also as the function is returning a type BOOL why not use TRUE and FALSE instead of 1 and 0?

    Your code can probably be shortened to
    Code:
    BOOL isShiftCaps()
    {
        return ((GetKeyState(VK_CAPITAL) & 0x0001) == 1) && ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000);
    }
    Thank you very much for help me @2kaud, although you hint is correct, but here still not work. I'll forget this code. Thank very much one more time to you and @VictorN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured