Introduction
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.
Background
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
Collapse
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
Example
Collapse
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
etc.
Screen keyboard has 122 constraints. &HD, H10, &H1B etc. are the key�s hexadecimal codes.
Screen keyboard functions
Collapse
Public Function whichbuttonpushed(ByVal _
sender As String) As String
The sender string gets the button's name when you click the button.
Example
Collapse
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
etc.
end select
The following function gets the numlockbutton names and controls the numlock key state:
Collapse
Public Function numlockfunc(ByVal numlock_key As String, _
ByVal open_close As Boolean) As String
Example
Collapse
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)
etc.
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)
etc.
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:
Collapse
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.
Example
Collapse
SetActiveWindow(8975651603260375040)
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
Collapse
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
Next
Me.Text = "MY SCREEN KEYBOARD" & Space(55) & _
DateTime.Now & Space(20) & processstring
End sub
Capture the screen
Collapse
Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
System.Threading.Thread.Sleep(200)
' 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)),
Bitmap)
p.Image = bmap
i += 1
p.Image.Save(
"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
screenshot()
Else
End If
License
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment