Click here to Skip to main content
16,016,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got a vc++ application to perform soft keyboard. If I have 2 button in my dialog. One for sending keystroke of a and another will act as shift key for generating A. My code is as follows

void CKeyBoardDlg::OnBnClickedButton33()  //for a
{
    keybd_event(0x41,0,0,0);
    keybd_event(0x41,0,KEYEVENTF_KEYUP,0);
}

void CKeyBoardDlg::OnBnClickedButton45()  //for shift
{
    if(m_nFirst==1)
    {
        m_nFirst=0;
        keybd_event(0x10,0,0x002,0);
    }
    else if(m_nFirst==0)
    {
        keybd_event(0x10,0,0,0);
        m_nFirst=1;
    }
}


My question is that once I click on the button45 shiftkey is in pressed state based on logic. So I can create A by pressing button33 next. But my problem is that when I click again on button45 the event is not working and hence it affects every keyboard shortcuts and activities. What is the problem??? Why is it not invoked?

Is there any another way to send capital letter by keystroke event(keybd_event).
Posted
Updated 10-May-11 14:50pm
v4
Comments
Albert Holguin 10-May-11 16:22pm    
edit: changed tags

Look at keybd_event() specification:
http://msdn.microsoft.com/en-us/library/ms646304%28v=vs.85%29.aspx[^]

Looks like you're never calling KEYEVENTF_KEYUP which is 0x0002 not 0x002.
 
Share this answer
 
I have changed 0x002 with 0x0002 and KEYEVENTF_KEYUP.But it is not working again.
 
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