击键发送大写字母和一些特殊符号 [英] keystroke sending for capital letters and some special symbols

查看:132
本文介绍了击键发送大写字母和一些特殊符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个vc ++应用程序来执行软键盘.我可以通过9向所有字母a到z以及1个 发送,包括0,退格键,空格键.但是现在的问题是我无法发送大写字母(A到Z)和类似!的键击! @#$等.下面是我的代码 ad ????? .对于小写字母,我已经编写了代码

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

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

    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


对于发送小写字母,效果很好,但不能发送大写字母.我们可以使用keybd_event做这件事吗?如果不是,是否可以使用SendInput函数.如果您知道此问题,请 ans answer .


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.

推荐答案

等.我的代码 ad ????? 以下.对于小写字母,我已经编写了代码
etc. My code ad ????? following. for small letters I have written the code
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

    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


对于发送小写字母,效果很好,但不能发送大写字母.我们可以使用keybd_event做这件事吗?如果不是,是否可以使用SendInput函数.如果您知道此问题,请 ans answer .用示例进行解释.


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.


我发现的一种方法是,您必须检查键状态
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)
{

}


但是我们如何获取shiftkey的按键.在我的shiftkey的按钮中,我编写了如下代码
//将布尔值声明为成员变量
//BOOL bShift;
//BOOL bCaps;
//初始化
//bShift = FALSE;
//bCaps = FALSE;

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;

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;
    }
}



对于字符,请说"a"我的代码,如下所示



For a char say ''a'' my code as follows

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

   }
    DestroyWindow();
}



亲爱的shilpi不使用getkeystate我可以发送大写字母.但是再次单击button45按钮单击事件不起作用.也就是说,我无法将大写字母写成小写字母.



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.


这篇关于击键发送大写字母和一些特殊符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆