Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Key capture using OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method

Key capture using OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 9307625
    wrote on last edited by
    #1

    See more: VC++ Dear All, I am working MFC Application, this application is compiled using VS2008. To capture the key pressed OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method is used. The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97". Even if the caps lock is "ON" the value i get is "65" when i press "A". The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys) as the OnKeyUp() is as MFC method, I am not sure how to solve this issue. Kindly help me and let me know if you require any more information. Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word. void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CString SBCommand; CString Temp; char *s = NULL; char strnChar[10]; /* Alphabets and Numerals passed to the command box */ if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57)) { pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); Temp.Format("%c",nChar); SBCommand += Temp; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand); /*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); SBCommand += (char*)nChar; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/ } }

    S J _ 3 Replies Last reply
    0
    • U User 9307625

      See more: VC++ Dear All, I am working MFC Application, this application is compiled using VS2008. To capture the key pressed OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method is used. The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97". Even if the caps lock is "ON" the value i get is "65" when i press "A". The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys) as the OnKeyUp() is as MFC method, I am not sure how to solve this issue. Kindly help me and let me know if you require any more information. Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word. void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CString SBCommand; CString Temp; char *s = NULL; char strnChar[10]; /* Alphabets and Numerals passed to the command box */ if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57)) { pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); Temp.Format("%c",nChar); SBCommand += Temp; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand); /*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); SBCommand += (char*)nChar; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/ } }

      S Offline
      S Offline
      Sivaraman Dhamodharan
      wrote on last edited by
      #2

      OnKeyDown: The key is Kept Down OnKeyUp: The Key is released The above two together form OnKeyPress All three will give the state of the Keys. OnChar is the best event for your expectation.

      Programming Article

      1 Reply Last reply
      0
      • U User 9307625

        See more: VC++ Dear All, I am working MFC Application, this application is compiled using VS2008. To capture the key pressed OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method is used. The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97". Even if the caps lock is "ON" the value i get is "65" when i press "A". The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys) as the OnKeyUp() is as MFC method, I am not sure how to solve this issue. Kindly help me and let me know if you require any more information. Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word. void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CString SBCommand; CString Temp; char *s = NULL; char strnChar[10]; /* Alphabets and Numerals passed to the command box */ if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57)) { pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); Temp.Format("%c",nChar); SBCommand += Temp; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand); /*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); SBCommand += (char*)nChar; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/ } }

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        The character value is a virtual-key[^] code. You can use GetKeyState(VK_SHIFT) to check if any shift key is pressed or not. Depending on your requirements, it may be better to handle WM_CHAR notifications (CWnd::OnChar()) rather than using key up/down notifications. Then you will get the character code of the key that was pressed.

        1 Reply Last reply
        0
        • U User 9307625

          See more: VC++ Dear All, I am working MFC Application, this application is compiled using VS2008. To capture the key pressed OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) method is used. The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97". Even if the caps lock is "ON" the value i get is "65" when i press "A". The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys) as the OnKeyUp() is as MFC method, I am not sure how to solve this issue. Kindly help me and let me know if you require any more information. Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word. void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CString SBCommand; CString Temp; char *s = NULL; char strnChar[10]; /* Alphabets and Numerals passed to the command box */ if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57)) { pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); Temp.Format("%c",nChar); SBCommand += Temp; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand); /*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand); SBCommand += (char*)nChar; pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/ } }

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          In addition to VK_SHIFT, you may also want to check the state with VK_CAPITAL.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++) (October 2009 - September 2013)

          Polymorphism in C

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups