使用 vb.net 调用屏幕键盘 (OSK)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42616132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:12:56 来源:igfitidea点击:
Call On-Screen Keyboard(OSK) using vb.net
提问by KiRa
I am using this code below to call On-Screen Keyboard(OSK)
我正在使用下面的代码来调用 On-Screen Keyboard(OSK)
Process.Start("C:\Windows\System32\OSK.EXE")
but as you can see below I got an error. But if I manually open it, it's working fine.
但正如你在下面看到的,我遇到了一个错误。但是如果我手动打开它,它工作正常。
And it is possible to call the OSK but only numeric display (0 - 9)
回答by Apoorva Vyas
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
回答by Ravi Patel
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
回答by Jorn
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

