GetKeyState(VK_CAPITAL) and GetKeyState(VK_SHIFT) together pressed to lowercase
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

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

  1. #1
    Join Date
    Apr 2014
    Posts
    24

    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 02:36 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

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

    What is Key?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    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 12:33 PM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Apr 2014
    Posts
    24

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center