|
-
Sep 9th, 2000, 01:34 PM
#1
Thread Starter
Hyperactive Member
Hi,
I've posted this before.....but haven't found a solution as yet.....so here I am re-posting.....
I am running a .exe file from my VB application. I need to detect when a key has been pressed and on detecting a keypress have to stop the .exe file. How do I detect a keypress in this case????
Also how do I deetect if the mouse has been clicked when the .exe file is running.
Am using VB6.
Thanx.
-
Sep 9th, 2000, 01:40 PM
#2
Use GetAsyncKeyState
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()
'If escape is pressed then quit
If GetAsyncKeyState(vbKeyEscape) Then Unload Me
End Sub
-
Sep 9th, 2000, 01:44 PM
#3
Thread Starter
Hyperactive Member
Megatron,
I need to stop the .exe file no matter which key is
pressed.
-
Sep 9th, 2000, 01:54 PM
#4
Simply loop through all the keys.
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()
'If any key is pressed then quit
For I = 3 To 255
If GetAsyncKeyState(I) Then Unload Me
Next I
End Sub
-
Sep 9th, 2000, 02:07 PM
#5
Thread Starter
Hyperactive Member
Megatron,
Tried ur code, used a timer with an interval of 10 secs....and in the form load event started the exe.
This is my code:
Code:
Public Sub End_exe()
Dim retval As Long
retval = FindWindow(vbNullString, "Flash")
SendMessage retval, WM_CLOSE, 0, 0
End
End Sub
Private Sub Timer1_Timer()
'If any key is pressed then quit
For I = 3 To 255
If GetAsyncKeyState(I) Then End_exe
Next I
End Sub
Flash --> name of the .exe file
The problem I'm facing is that the exe starts and then stops immediately. Any ideas?? Must I refresh the key states or anything like that???
Thanx.
[Edited by rammy on 09-09-2000 at 03:16 PM]
-
Sep 10th, 2000, 01:29 AM
#6
Thread Starter
Hyperactive Member
-
Sep 10th, 2000, 01:45 AM
#7
Try this - Set the Form's KeyPreview property to true and use this code:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
For i = 3 To 255
If KeyAscii = i Then End_exe
Next i
End Sub
-
Sep 10th, 2000, 02:06 AM
#8
Thread Starter
Hyperactive Member
Mathew,
That will work if I have detect a keypress on the form. But I have to detect a keypress in an external application.
-
Sep 10th, 2000, 01:15 PM
#9
Thread Starter
Hyperactive Member
doesn't anybody have any idea????????????? :-((
-
Sep 10th, 2000, 07:25 PM
#10
Addicted Member
Try this code.
/code
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim ikey As Integer
Dim bkey(255) As Byte
Dim iasc As Long
For ikey = 0 To 255
'Use GetAsyncKeyState to Monitor Keypress From Anywhere in the O/S.
If GetAsyncKeyState(ikey) And ikey <> VK_SHIFT Then Exit For
Next
If ikey < 256 Then
Call GetKeyboardState(bkey(0))
Call ToAscii(ikey, 0&, bkey(0), iasc, 0&)
If iasc Then
'Store Keypress to Log Here
Text1.Text = Text1.Text + Chr(iasc)
End If
DoEvents
While GetAsyncKeyState(ikey)
'Wait for Key to be Released
Wend
End If
End Sub
code/
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
|