【问题标题】:Call On-Screen Keyboard(OSK) using vb.net使用 vb.net 调用屏幕键盘(OSK)
【发布时间】:2017-03-06 01:20:08
【问题描述】:

我正在使用下面的代码调用On-Screen Keyboard(OSK)

Process.Start("C:\Windows\System32\OSK.EXE")

但正如您在下面看到的,我遇到了一个错误。但是如果我手动打开它,它工作正常。

并且可以调用OSK但只能显示数字(0 - 9)

【问题讨论】:

  • 你的问题是什么?
  • @Neolisk 无法加载我的 OSK .. 如果它会加载。可以只加载数字吗?。
  • 我认为通过这样的内置方法控制用户可以输入的内容是不可能的。您可以编写自己的键盘。如果您更详细地描述您的需求,人们可能会提出更多选择。
  • @Neolisk 我也在考虑为#(0-9)创建一个 10 个按钮。像上图一样调用 OSK 时,我只是将问题包含在我的问题中
  • 这适用于 Windows 10 吗?

标签: vb.net vb.net-2010 on-screen-keyboard


【解决方案1】:
Public Class Form1

    Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
    Declare Function Wow64EnableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
    Private osk As String = "C:\Windows\System32\osk.exe"
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim old As Long
        If Environment.Is64BitOperatingSystem Then
            If Wow64DisableWow64FsRedirection(old) Then
                Process.Start(osk)
                Wow64EnableWow64FsRedirection(old)
            End If
        Else
            Process.Start(osk)
        End If
    End Sub
End Class

【讨论】:

  • 如果您在代码中添加说明性文字,对其他用户会更有帮助。
【解决方案2】:
Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
Declare Function Wow64EnableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
Private osk As String = "C:\Windows\System32\osk.exe"
Private pOSK As Process = Nothing

Public Sub Keyboard_Show()
    'An instance is running => Dan wordt pOSK het bestaande proces
    For Each pkiller As Process In Process.GetProcesses
        If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then pOSK = pkiller
    Next

    'If no instance of OSK is running than create one depending on 32/64 bit
    For Each pkiller As Process In Process.GetProcesses
        If Not (String.Compare(pkiller.ProcessName, "osk", True) = 0) And (pOSK Is Nothing) Then

            Dim old As Long
            If Environment.Is64BitOperatingSystem Then
                '64 Bit
                If Wow64DisableWow64FsRedirection(old) Then
                    pOSK = Process.Start(osk)
                    Wow64EnableWow64FsRedirection(old)
                End If
            Else
                '32 Bit
                pOSK = Process.Start(osk)
            End If
            Exit For
        End If
    Next
End Sub

'-------------------------------------------------
'--- Hide On Screen Keypad mbv process threads ---
'--- 05-07-2018                                ---
'-------------------------------------------------
Public Sub Keyboard_Hide()
    For Each pkiller As Process In Process.GetProcesses
        If String.Compare(pkiller.ProcessName, "osk", True) = 0 And Not (pOSK Is Nothing) Then

            ' Terminate process
            pOSK.Kill()
            Exit For
        End If
    Next

    'Wait untill proces is really terminated
    For intStap As Integer = 1 To 10
        For Each pkiller As Process In Process.GetProcesses
            If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then
                Thread.Sleep(1000)
            Else
                pOSK = Nothing
                Exit For
            End If
        Next
    Next intStap
End Sub

【讨论】:

  • 虽然此代码可以回答问题,但提供有关其解决问题的方式和原因的信息可提高其长期价值。
【解决方案3】:
Private oskProcess As Process

Private Sub openButton_Click(ByVal sender As System.Object, ByVal e As 
                            System.EventArgs) Handles openButton.Click
 If Me.oskProcess Is Nothing Then
   If Me.oskProcess IsNot Nothing AndAlso Me.oskProcess.HasExited Then
            Me.oskProcess.Close()
   End If
        Me.oskProcess = Process.Start("osk")
 End If
End Sub

【讨论】:

    猜你喜欢
    • 2012-03-06
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多