Click here to Skip to main content
14,489,132 members

Screen Keyboard

Rate this:
4.40 (30 votes)
Please Sign up or sign in to vote.
4.40 (30 votes)
23 Jun 2005
Win32 API

Image 1


The screen keyboard can write all the fields (password field, address bar, Notepad etc.). You can use Ctrl, Shift, Alt, Altgr, Esc, (Alt + f4) or any other keyboard events. You can also use the screen keyboard for opening Notepad, WordPad, Winamp, Outlook, Internet Explorer, Task Manager, CDROM tray, calculator, run window, search, media player and your Hotmail inbox. The program shows your MSN messenger contact list along with the names of all the songs you have listened to, simultaneously. The screen keyboard looks like Microsoft screen keyboard, but it has some extra properties.


My project heavily uses Win32 API (Application Programming Interface) .The screen keyboard contains low level language properties. I have seen similar samples written in C++, but they cannot write every where. I wanted the screen keyboard to be written in VB.NET because I could not find any code here in CodeProject or any other site that fulfilled my requirements. Almost all other similar programs were written in C++, and none of them fully met my requirements. The API text viewer contains all the Windows API functions and constraints. The API text viewer also displays all your requirements when you use it.

Windows API references

  • File, Memory, Process, Threading, Time, Console and Comm control(kernel32.dll)
  • Windows handling, and Windows UI control(user32.dll)
  • Graphics and Imaging(gdi32.dll)
  • Audio, Video, and Joystick control (winmm.dll)
  • Registry, Event Log, Authentication, and Services(advapi32.dll)
  • Printing (winspoll.dll)
  • Asian characters support(imm32.dll)
  • Executing processes(shell32.dll)
  • Winsock, Windows berkley socket support(wsock32.dll)
  • WNet* Instrumentation (mpr.dll)
  • Common Dialog control(comdlg32.dll)
  • Windows Network support(netapi32.dll)
  • Windows Compression(lz32.dll)
  • Common Controls(comctl32.dll)
  • Versioning support (version.dll)
  • Object linking and embedding(ole32.dll)

Screen keyboard

API functions for screen keyboard

Public Declare Function SetActiveWindow Lib "user32" Alias _
                   "SetActiveWindow"(ByVal hwnd As Long) As Long

Declare Function keybd_event Lib "user32" Alias "keybd_event" _
     (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
     ByVal dwExtraInfo As Long) As Long

Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
     (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
     ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) _
     As Integer

API constraints for screen keyboard

Const KEYEVENTF_KEYUP = &H2 ' Release key
Const VK_RETURN = &HD 'enter
Const VK_SHIFT = &H10 'Shift
Const VK_CONTROL = &H11 'Ctrl
Const VK_CAPITAL = &H14 'capslock
Const VK_ESCAPE = &H1B 'escape

Screen keyboard has 122 constraints. &HD, H10, &H1B etc. are the key’s hexadecimal codes.

Screen keyboard functions

Public Function whichbuttonpushed(ByVal _
                       sender As String) As String

The sender string gets the button's name when you click the button.

Select Case _sender
    Case "btna" 
        keybd_event(VK_A, 0, 0, 0) 'send a key 
        keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0)'release a key 
        shiftrelease() 'release shift 
        altrelease() 'release alt 
        leftaltrelease() 'release altgr
    Case "btnb"
        keybd_event(VK_B, 0, 0, 0) 'send b key
        keybd_event(VK_B, 0, KEYEVENTF_KEYUP, 0)'release b key
        shiftrelease() 'release shift 
        altrelease() 'release alt 
        leftaltrelease() 'release altgr 
end select

The following function gets the numlockbutton names and controls the numlock key state:

Public Function numlockfunc(ByVal numlock_key As String, _
                      ByVal open_close As Boolean) As String
If open_close = False Then 'numlock opened
    Select Case numlock_key
        Case "btnnumlockdiv"
            keybd_event(VK_DIVIDE, 0, 0, 0)
            keybd_event(VK_DIVIDE, 0, KEYEVENTF_KEYUP, 0)
    End Select
Else 'numlock closed
    Select Case numlock_key
        Case "btnnumlockdiv"
            keybd_event(VK_DIVIDE, 0, 0, 0)
            keybd_event(VK_DIVIDE, 0, KEYEVENTF_KEYUP, 0)
    End Select 
End If

Screen keyboard set focus function

The keyboard sets the focus to the active window when the button is clicked. The active window introducer number is (8975651603260375040). I found this number using the GetActiveWindow function:

Public Declare Function GetActiveWindow Lib "user32" _
                      Alias "GetActiveWindow" () As Long

The following code snippet is very important for the screen keyboard because the function SetActiveWindow sets the focus to the active window.


The SetActiveWindow function is used after the button is clicked.

Messenger API

.NET contains Interop.MessengerAPI. I have included Interop.MessengerAPI.dll as reference and used the singin method. In addition to this MessengerAPI contains the openinbox property. Openinbox enables us to go to the Hotmail inbox directly if any one signs in on the computer.

Get the Winamp process

Dim processes() As process
Dim process As New process
Dim processstring As String
Sub Timer1_Tick
Dim mycoll As New Collection
processes = process.GetProcesses
For Each process In processes
    mycoll.Add(process, process.Id.ToString)
    If process.ProcessName = "winamp" Then
        processstring = process.MainWindowTitle 
        'gets song’s name(MainWindowTitle)
        Exit For
    End If
Me.Text = "MY SCREEN KEYBOARD" & Space(55) & _
DateTime.Now & Space(20) & processstring
End sub

Capture the screen

Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
' To have time to catch the clipboard
Static i As Integer
Dim data As IDataObject
data = Nothing
data = Clipboard.GetDataObject()
Dim bmap As Bitmap
Dim p As New PictureBox
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
    bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), 
    p.Image = bmap
    i += 1
      "C:\Documents and Settings\All Users\Desktop\Screenshot " _
                  & i.ToString & " .jpg", Imaging.ImageFormat.Jpeg)
End If
If Not File.Exists(
      "C:\Documents and Settings\All Users\Desktop\Screenshot " _
                                       & i.ToString & " .jpg") Then
End If


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Turkey Turkey
No Biography provided

Comments and Discussions

QuestionI need help to port web based G7 onscreen-keypad to Windows Native application. Pin
Member 815507611-Aug-12 1:22
MemberMember 815507611-Aug-12 1:22 
Question?? Pin
lobotomy10-Apr-10 1:29
professionallobotomy10-Apr-10 1:29 
Generala simple question Pin
danceoften14-Dec-09 3:15
Memberdanceoften14-Dec-09 3:15 
GeneralPInvokeStackImbalance was detected Pin
chabdesign21-Feb-07 5:11
Memberchabdesign21-Feb-07 5:11 
GeneralRe: PInvokeStackImbalance was detected Pin
Eduardo Carstensen19-Jul-13 8:51
MemberEduardo Carstensen19-Jul-13 8:51 
QuestionError Message While Trying To Run This Code Pin
Faruk Ansari6-Dec-06 7:58
MemberFaruk Ansari6-Dec-06 7:58 
AnswerRe: Error Message While Trying To Run This Code Pin
Bob Beaubien18-Sep-09 5:22
MemberBob Beaubien18-Sep-09 5:22 
AnswerRe: Error Message While Trying To Run This Code Pin
Marktw021-Nov-09 18:36
MemberMarktw021-Nov-09 18:36 
GeneralProblem in Web Browser Control Pin
rajansarna14-Nov-06 20:55
Memberrajansarna14-Nov-06 20:55 
QuestionKeys do not press Pin
cowman8-Sep-06 15:12
Membercowman8-Sep-06 15:12 
AnswerRe: Keys do not press Pin
Kakkaduz17-Oct-07 23:49
MemberKakkaduz17-Oct-07 23:49 
GeneralRe: Keys do not press Pin
ketnoibanbe26-May-09 23:58
Memberketnoibanbe26-May-09 23:58 
GeneralError with ComboBox in DropDown Style Pin
Chili55523-Nov-05 23:37
MemberChili55523-Nov-05 23:37 
GeneralRe: Error with ComboBox in DropDown Style Pin
poman318-Sep-10 2:13
Memberpoman318-Sep-10 2:13 
GeneralSetActiveWindow(8975651603260375040) Pin
avnersimon1-Oct-05 7:59
Memberavnersimon1-Oct-05 7:59 
QuestionRe: SetActiveWindow(8975651603260375040) Pin
Dic197822-Apr-10 4:43
MemberDic197822-Apr-10 4:43 
Generalreading the Pressed key Pin
Amir Jalaly2-Jul-05 20:58
MemberAmir Jalaly2-Jul-05 20:58 
GeneralBloq Num Pin
Vitoto2-Jul-05 16:00
MemberVitoto2-Jul-05 16:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 23 Jun 2005


78 bookmarked