简体   繁体   English

VB.NET如何使用SendMessage发送密钥46(Chr(46))

[英]VB.NET How to send key 46 (Chr(46)) with SendMessage

I am Automating IBM iSeries Emulators using VB.net, created GUI that embeds the external iSeries Emulator Window in a WindowsForm Panel using the "SetParent" API .. To communicate with the iSeries Window I use the SendMessage API to send Key's to the Screen. 我正在使用VB.net自动化IBM iSeries模拟器,创建了GUI,该GUI使用“ SetParent” API将外部iSeries模拟器窗口嵌入WindowsForm面板中。要与iSeries窗口进行通信,我使用SendMessage API将密钥发送到屏幕。 I am aware of the sendkeys.keys in .net, but this way I dont have to SetForegroundWindow and reactivate my Form. 我知道.net中的sendkeys.keys,但是通过这种方式,我不必SetForegroundWindow并重新激活我的窗体。

My program reads the output of a scale and validates if the received data is good, if so it will send the output to the iSeries Screen using this code (UserApi is my Lib): 我的程序读取秤的输出并验证接收到的数据是否良好,如果是,它将使用以下代码将输出发送到“ iSeries屏幕”(UserApi是我的Lib):

For Each element As Char In CStr(txtto400.Text)
    UserApi.SendMessage(as400WindowHandle, 256, CType(Convert.ToInt32(element), IntPtr), CType(0, IntPtr))
Next

I done this a few times on other projects and this method works good, but in my TextBox (txtto400.Text) my weight has a Value like "000.88 KG". 我在其他项目上做了几次,这种方法效果很好,但是在我的TextBox(txtto400.Text)中,我的权重值为“ 000.88 KG”。 SendMessage will not send the key "46" which is a period (.) Instead it would be "00088 KG" SendMessage不会发送密钥“ 46”,它是句点(。),而是“ 00088 KG”

Does anyone have an idea why this dont work? 有谁知道为什么这不起作用? Any suggestions what I could do? 有什么建议我可以做什么?

EDIT: 编辑:

Thanks to Paul B. which gave me the hint. 感谢Paul B.给了我提示。

Here is how I resolved it. 这是我解决的方法。

My SendMessage function looks like this: 我的SendMessage函数如下所示:

<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendMessage( _
   ByVal hwnd As IntPtr, _
   ByVal wMsg As UInt32, _
   ByVal wParam As IntPtr, _
   ByVal lParam As IntPtr) As IntPtr
End Function

I created a variable that holds the VK_OEM_PERIOD: 我创建了一个包含VK_OEM_PERIOD的变量:

Public Const VK_OEM_PERIOD = &HBE

Created a Function that will check the Chr: 创建了一个可以检查Chr的函数:

Public Function vk_key(key As Char) As Integer
 Select Case key
     Case Is = Chr(46)
         Return VK_OEM_PERIOD
     Case Else
        Return AscW(key)
 End Select
End Function

here is how I pass it to the iSeries Window: 这是我将其传递给“ iSeries窗口”的方法:

For Each element As Char In txtto400.Text
   UserApi.SendMessage(as400WindowHandle, 256, vk_key(element), 0)
Next

The WM_KEYDOWN message expects "The virtual-key code of the nonsystem key" as wParam (see MSDN ). WM_KEYDOWN消息期望“非系统密钥的虚拟密钥代码”为wParam(请参见MSDN )。

This happens to correspond to the key character's ASCII value for alphanumeric signs but not for all other keys. 这恰好对应于字母数字符号的键字符的ASCII值,但不适用于所有其他键。 For a period I think you need to send VK_OEM_PERIOD . 在一段时间内,我认为您需要发送VK_OEM_PERIOD

You can find the table of virtual-key codes here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx 您可以在此处找到虚拟键代码表: http : //msdn.microsoft.com/zh-cn/library/windows/desktop/dd375731%28v=vs.85%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM