• COM to PS2(将串口读到的信息直接转换成键盘的输入信息)


    1、使用MSComm读串口信息

    Private Sub Command1_Click()

        If Me.MSComm1.PortOpen = True Then Me.MSComm1.PortOpen = False
       
        Me.MSComm1.CommPort = Me.cbCom.ListIndex + 1
        Me.MSComm1.Settings = Me.txtSettings.Text
        Me.MSComm1.InputLen = 0
        Me.MSComm1.PortOpen = True

    End Sub

    Private Sub MSComm1_OnComm()
    Dim readline As String
        Select Case MSComm1.CommEvent
            Case comEvReceive
                '开始接收
                readline = MSComm1.Input
                  
                formatData readline
            Case Else
        End Select
    End Sub

    2、将读到的信息做些处理

    Private Sub formatData(ByVal str As String)
        '判断字符串是否以回车换行结束,如果是去掉
        If Asc(Mid(str, Len(str), 1)) = 10 And Asc(Mid(str, Len(str) - 1, 1)) = 13 Then
            str = Mid(str, 1, Len(str) - 2)
        End If
        '添加回车换行功能
        If selectEnter Then str = str + Chr(13) + Chr(10)
        '添加Tab功能
        If selectTab Then str = str + Chr(9)
        sendstring (str)
    End Sub

    3、出发键盘信息

    Private Sub sendstring(ByVal str As String)
        SendKeys str
    End Sub

    c#

     private void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                string data = "";
                data = sp.ReadLine();

                sendData(data);
            }

            private void sendData(string data)
            {
                SendKeys.SendWait(data);
                if (this.checkBox1.Checked)
                {
                    SendKeys.SendWait("{enter}");
                }
                if (this.checkBox2.Checked)
                {
                    SendKeys.SendWait("{tab}");
                }
            }

    SendKeys.Send(data)不能用。

  • 相关阅读:
    03:信号与槽,以字体修改为例
    赞不绝口点赞器原作者的撤项信
    钉钉魔铃 铃声切换器 1.0 项目失败
    KC开发组官方网站
    搜索引擎知识
    现在的手机厂家真浮躁
    02:QT的第一个程序
    第一次做编程语言的英语阅读理解
    mysql 报错[Err] [Dtf] 1292
    Mysql 精确查询是否字段中包含某个字符串
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/1503781.html
Copyright © 2020-2023  润新知