论文无忧网提供:计算机毕业论文范文|计算机毕业设计|计算机毕业论文
栏目导航 ASP Java Web .NET VB6.0 JAVA VC VF DELPHI PB 计算机网络 计算机科学与技术 PHP 安卓APP 其他 C# 代写论文
当前位置: > 计算机 > 计算机科学与技术 >

远程控制软件的设计与开发-控制远程按键(论文+程序)

5.2.2 模拟按键

函数keybd_event()综合一个按键事件,系统用这个事件产生WM_KEYUP或WM_KEYDOWN消息.在WindowsNT下,该函数被SendInput()所代替.函数keybd_event()的原型如下: 内容来自www.paper51.com

VOID keybd_event(BYTE bVk,BYTEbScan,DWORD dwFlags,DWORD dwExtraInfo); 内容来自www.paper51.com

函数keybd_event()有4个参数,其中参数bVk指所按键的虚拟键值.取值范围在1至254之间。常见的特殊键值有:Tab(9),Shift(16),Ctrl(17),Alt(18),CapsLock(20),Esc(27),Win(91,92),NumLock(144)及ScrollLock(145)等. 内容来自www.paper51.com

参数bScan指所按键的扫描码。

paper51.com

参数dwFlags指函数操作标志位集合,应用程序可以检测这个值。它可以取以下值。

http://www.paper51.com

KEYEVENTF_EXTENDEDKEY:如果指定该值,则键盘扫描码加一个前缀(224)。 paper51.com

KEYEVENTF_KEYUP:如果指定该值,则键释放,否则,键一直被按下。

copyright paper51.com

参数dwExtralnfo指向一个附加的与键值有关联的32位值。

copyright paper51.com

5.3具体代码

http://www.paper51.com

由于篇幅有限,这里只列出了部分重要代码。 paper51.com

服务器端套接字的创建,绑定,连接: copyright paper51.com

char chName[256]; copyright paper51.com

sockaddr_in addr; 内容来自论文无忧网 www.paper51.com

hostent* pEnt = NULL; http://www.paper51.com

int addrlen = 0, nRet = 0; copyright paper51.com

nRet = ::gethostname(chName, 256);

copyright paper51.com

       if(nRet== 0) http://www.paper51.com

       { 内容来自www.paper51.com

              m_sckServer= socket(AF_INET, SOCK_STREAM, 0); http://www.paper51.com

              if(m_sckServer!= INVALID_SOCKET) http://www.paper51.com

              { paper51.com

                     pEnt= ::gethostbyname(chName); 内容来自论文无忧网 www.paper51.com

                     if(pEnt)

内容来自www.paper51.com

                  {

http://www.paper51.com

                         addr.sin_family= AF_INET;

内容来自论文无忧网 www.paper51.com

                         addr.sin_port= htons(m_uPort); paper51.com

                         addr.sin_addr.s_addr= INADDR_ANY;

内容来自www.paper51.com

                         nRet= ::bind(m_sckServer, (sockaddr*)&addr, sizeof(addr)); http://www.paper51.com

                         paper51.com

                         if(nRet!= SOCKET_ERROR) 内容来自论文无忧网 www.paper51.com

                         {

copyright paper51.com

                                nRet= ::listen(m_sckServer, SOMAXCONN);

http://www.paper51.com

                                if(nRet!= SOCKET_ERROR)

内容来自www.paper51.com

                                {

paper51.com

                                       addrlen= sizeof(addr);

copyright paper51.com

                            TRACE(_T("开始了服务,等待客户......\n"));

内容来自www.paper51.com

             m_sckClient[0] = ::accept(m_sckServer, (sockaddr*)&addr,&addrlen); http://www.paper51.com

            if(m_sckClient[0] != INVALID_SOCKET) 内容来自www.paper51.com

             { 内容来自论文无忧网 www.paper51.com

                     //为了同步 内容来自论文无忧网 www.paper51.com

              ::PL_SendSocketData(m_sckClient[0], NULL, 0, PL_TEMP, MSG_OOB);

内容来自论文无忧网 www.paper51.com

              }

内容来自www.paper51.com

             m_sckClient[1] = ::accept(m_sckServer, (sockaddr*)&addr,&addrlen); paper51.com

             if(m_sckClient[0] != INVALID_SOCKET && m_sckClient[1] != INVALID_SOCKET) 内容来自www.paper51.com

                    TRACE(_T("客户连接上了.......\n")); 内容来自论文无忧网 www.paper51.com

服务器端关闭套接字: paper51.com

BOOL CSocketThread::ExitServer()

内容来自论文无忧网 www.paper51.com

{

内容来自论文无忧网 www.paper51.com

       TRACE(_T("退出服务,重新等待连接......\n")); 内容来自www.paper51.com

       if(g_pSendDIBThread!= NULL)

copyright paper51.com

       { http://www.paper51.com

              ::TerminateThread(g_pSendDIBThread->m_hThread,0); 内容来自www.paper51.com

              ::WaitForSingleObject(g_pSendDIBThread->m_hThread,INFINITE); paper51.com

              g_pSendDIBThread= NULL;

copyright paper51.com

       }

http://www.paper51.com

       if(g_pWaitCommandThread!= NULL)

paper51.com

       {

内容来自论文无忧网 www.paper51.com

              ::TerminateThread(g_pWaitCommandThread->m_hThread,0); http://www.paper51.com

              ::WaitForSingleObject(g_pWaitCommandThread->m_hThread,INFINITE);

内容来自www.paper51.com

              g_pWaitCommandThread= NULL; copyright paper51.com

       } paper51.com

       if(m_sckClient[0]!= INVALID_SOCKET)

copyright paper51.com

       { 内容来自www.paper51.com

              ::closesocket(m_sckClient[0]);

paper51.com

       } 内容来自www.paper51.com

       if(m_sckClient[1]!= INVALID_SOCKET) http://www.paper51.com

       {

paper51.com

              ::closesocket(m_sckClient[1]);

http://www.paper51.com

       }

http://www.paper51.com

       if(m_sckServer!= INVALID_SOCKET) 内容来自论文无忧网 www.paper51.com

       { 内容来自论文无忧网 www.paper51.com

              ::closesocket(m_sckServer);

copyright paper51.com

       }

copyright paper51.com

       m_sckClient[0]= INVALID_SOCKET; http://www.paper51.com

       m_sckClient[1]= INVALID_SOCKET;

内容来自www.paper51.com

       m_sckServer= INVALID_SOCKET;

内容来自论文无忧网 www.paper51.com

       returnTRUE; 内容来自论文无忧网 www.paper51.com

}

paper51.com

------分隔线----------------------------
联系方式