Click here to Skip to main content
15,884,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an vc++ application to perform softkeyboard.I could sent keystrock for all letters a to z and 1 th through 9 including 0, backspace, space. But now the problem is that i cant send the keystroke for capital letter(A to Z) and symbols like ! @ # $ etc. My code ad ????? following. for small letters I have written the code
C++
keybd_event(0x51,0,0,0);//keystrock when press the button
keybd_event(0x51,0,KEYEVENTF_KEYUP,0);//keystrock when release the button

for capital letter
C++
    UINT keyVirtualCode=VkKeyScan('Q');//getting virtualcode
CString str;
str.Format(_T("%i"),keyVirtualCode);//convert to string
//AfxMessageBox(str);//display the virtualcode
    keybd_event(0x151 ,0,0,0);//keystrock when press the button
    keybd_event(0x151,0,KEYEVENTF_KEYUP,0);//keystrock when release the button

For sending small letters it works well, but can't send capital letters. Can we do this thing using keybd_event. If not, can it by using SendInput function. Please ans answer for this que question if you know. explain with example.
Posted
Updated 10-May-11 2:17am
v3
Comments
#realJSOP 10-May-11 8:18am    
DO NOT ABBREVIATE OR USE TEXTSPEAK. It just pisses most of us off.

One way that I found is that you have to check the keystate
int nShftKeyState = GetKeyState(VK_SHIFT);
int nCapsKeyState = GetKeyState(VK_CAPITAL);

Check if shift key and caps lock is pressed. Sample code is shown below:

if(nShftKeyState & 0xff00)
{

}
 
Share this answer
 
But how we can obtain shiftkey's keystrock.In my shiftkey's button i have written the code as follows
// declare bool value as a member variable
//BOOL bShift;
//BOOL bCaps;
// initialize it
//bShift = FALSE;
//bCaps = FALSE;

C#
void CKeyBoardDlg::OnBnClickedButton45()//for shiftkey
{
    if(m_nFirst==1)
    {
        m_nFirst=0;
        bShift = FALSE;
        keybd_event(0x10,0,0x002,0);//releasing the button
    }
    else if(m_nFirst==0)
    {
        bShift = TRUE;
        keybd_event(0x10,0,0,0);//press down the key or button
        m_nFirst=1;
    }
}


For a char say 'a' my code as follows

C#
void CKeyBoardDlg::OnBnClickedButton33()//a
{
   if(bShift)
   {
    keybd_event(0x41,0,0,0);
    keybd_event(0x41,0,KEYEVENTF_KEYUP,0);
   }
   else
   {
     //capital A

   }
    DestroyWindow();
}


Dear shilpi without using getkeystate i could send caps.but again clicking on the button45 button click event is not working.that is i cant written caps to small letter.
 
Share this answer
 
v4
Comments
#realJSOP 10-May-11 8:19am    
Learn how to use the pre block around your code snippets.
ShilpiP 10-May-11 8:38am    
Oh !! These are all buttons. Take one bool value bShift = false as a member variable. When shift key is pressed than bShift will be true and if "a" button is pressed than check if bShift is true than send "A".
ShilpiP 10-May-11 8:46am    
I am updating your solution please check.
Important note:

Note This function [keybd_event — SA] has been superseded. Use SendInput instead.
See http://msdn.microsoft.com/en-us/library/ms646304(v=vs.85).aspx[^].

So, use SendInput. It's better and works like a charm.
See http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900