Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On-Screen Keyboard 5

Status
Not open for further replies.

TOMBUGGY

Programmer
Oct 4, 2000
36
0
0
US
I wish to incorporate an on-screen keyboard on selected forms in a VB project. I realize that I can turn on the Microsoft On-Screen Keyboard (osk.exe) but how do I turn it on and off selectively? Also, is there a 3rd party control or documented VB code for an on-screen keyboard?
 
You can use Shell to start it.
There are various 'Kill Application' around routines that will stop it. Such as (author unknown)
Code:
START
x=shell("osk.exe",true)

STOP
'At head of code
Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12

' Ask Windows for the list of tasks.
Public Sub TerminateTask()
    Target = "osk.exe"
    EnumWindows AddressOf EnumCallback, 0
End Sub

Private Target As String
' Check a returned task to see if we should
' kill it.
Public Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long

    ' Get the window's title.
    length = GetWindowText(app_hWnd, buf, Len(buf))
    title = Left$(buf, length)

    ' See if this is the target window.
    If InStr(title, Target) <> 0 Then
        ' Kill the window.
        SendMessage app_hWnd, WM_CLOSE, 0, 0
    End If

    ' Continue searching.
    EnumCallback = 1
End Function
 
Sorry, I just tested the link and it fails. I found what I was trying to link to in this forum. Try a search of "Terminate a Shelled To Program" (without the quote marks).
 
Here's an alternative for both shelling and terminating the on screen keyboard:
Code:
[blue]Option Explicit

Public myExec As Object

Private Sub Command1_Click()
    Set myExec = CreateObject("wscript.shell").Exec("osk")
End Sub

Private Sub Command2_Click()
    myExec.Terminate
End Sub[/blue]
 
TOMBUGGY:
Side note: The easy way to create a link to a different thread is to just copy/paste the thread number shown just below the subject. It automatically expands to the link. Using this thread as an example, if you put the text [ignore]thread222-1589849[/ignore], it will automatically expand to the link: thread222-1589849

Same works for the forumxxx numbers below the forum name. Click the "Process TGML" link toward the bottom of the page for even more info.
 
I have found a very good 3rd Party application - the Mount Focus Keyboard Designer. It's much more flexible and easier to handle than the Windows OSK.
 
Hey strongm,

this definitely qualifies as "adhering to the KISS standard".

Nice!
[thumbsup2]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I figuered I'd tri Strongm's code. It worked fine so I decided to try and use the OSB and put text into text1.
It worked fine with keypress as below

Private Sub Command1_KeyPress(KeyAscii As Integer)
Text1.Text = Text1.Text + vbCrLf
End Sub

But when I tried to multi=lines with this code only first keystroke went to text box. Can someone help?

Private Sub Command1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn
Text1.Text = Text1.Text + vbCrLf
Case Else
Text1.Text = Text1.Text & Chr(KeyAscii)
End Select
End Sub

End Sub
 
I think you are over complicating it.

Make sure the textbox has multiline set to true and set the focus to the textbox.
I tested it using strongm's code with the setfocus to the textbox and it worked.

Code:
Option Explicit

Public myExec As Object

Private Sub Command1_Click()
    Set myExec = CreateObject("wscript.shell").Exec("osk")
[COLOR=blue]    text1.SetFocus[/color]
End Sub

Private Sub Command2_Click()
    myExec.Terminate
End Sub
 
That sure did it. That's the difference between a pro and a non-pro. The pro always does it the easuer, most fluid way. way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top