|
-
Sep 27th, 2008, 08:54 PM
#1
Thread Starter
Addicted Member
VB 6.0: Keypress from another app?
How would you detect keypresses when another applacation has focus?
For example Ctrl-v.
I'm trying to make a 3ed party pasting program for a game called PlaneShift that dosen't currently have any copy or past support.
-
Sep 28th, 2008, 09:48 AM
#2
Fanatic Member
Re: VB 6.0: Keypress from another app?
How can a program receive a keyboard input if the program does not have Focus?
Or do you mean, prog-A receive a keyboard input and send it to prog-b ?
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
-
Sep 28th, 2008, 06:30 PM
#3
Re: VB 6.0: Keypress from another app?
Boys,
you can send a CTRL + V to a form even if it does not have focus as follows.
Code:
SendMessage(hwnd,WM_CHAR, 22, 0, 0) ' Ctrl+c =3 , Ctrl+X=24, ctrl + v=22
-
Sep 28th, 2008, 09:42 PM
#4
Re: VB 6.0: Keypress from another app?
I believe I've seen code for hooking keyboard events, even when your own app doesn't have focus.
But I've never used it.
Try searching for 'Key Logger' code
-
Sep 29th, 2008, 10:45 AM
#5
Thread Starter
Addicted Member
Re: VB 6.0: Keypress from another app?
Longwolf has the idea.
and its
How can a program receive a keyboard input if the program does not have Focus?
-
Sep 29th, 2008, 11:45 AM
#6
Re: VB 6.0: Keypress from another app?
here's a search I did at PSC. May have something you can use
http://www.planet-source-code.com/vb...=Keyboard+hook
-
Sep 29th, 2008, 12:35 PM
#7
Re: VB 6.0: Keypress from another app?
Wouldn't something like this work?
Code:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Static KeysInUse As Boolean
If GetAsyncKeyState(vbKeyControl) < 0 And GetAsyncKeyState(vbKeyV) < 0 Then
If KeysInUse = False Then
KeysInUse = True
Debug.Print "Control+V Pressed"
' Call Your Sub/Function here
Exit Sub
End If
Else
KeysInUse = False
End If
End Sub
-
Oct 4th, 2008, 04:14 PM
#8
Thread Starter
Addicted Member
Re: VB 6.0: Keypress from another app?
Is there anyway to make it more event driven?
-
Oct 4th, 2008, 05:21 PM
#9
Fanatic Member
Re: VB 6.0: Keypress from another app?
Does the program have focus?
If not, Timer, or something needs to be sent to it so an event will occur.
How can an event happen?
Timer, mouse move, key pressed, program received somthing via 'SendMessage',.....
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
-
Oct 4th, 2008, 05:47 PM
#10
Thread Starter
Addicted Member
Re: VB 6.0: Keypress from another app?
The game would have the focus, so no.
-
Oct 4th, 2008, 06:02 PM
#11
Re: VB 6.0: Keypress from another app?
You mean to say that you want to detect if ctrl+v is pressed while the game is in focus?
-
Oct 4th, 2008, 06:13 PM
#12
Thread Starter
Addicted Member
Re: VB 6.0: Keypress from another app?
Correct.
Edgemeal's method works, but the timer needs to be set to a very fast speed in order for the program to respond to it. Right now I have the timer set to 10.
-
Oct 5th, 2008, 02:35 AM
#13
Addicted Member
Re: VB 6.0: Keypress from another app?
how about a global hotkey
most likely you want to detect a combination of keys being pressed - a hotkey it doesnt matter which app has focus.
-
Oct 5th, 2008, 02:56 AM
#14
Re: VB 6.0: Keypress from another app?
Have you tried the suggestion of longwolf in post #6?
-
Jul 12th, 2009, 07:46 PM
#15
New Member
Re: VB 6.0: Keypress from another app?
 Originally Posted by Edgemeal
Wouldn't something like this work?
Code:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Static KeysInUse As Boolean
If GetAsyncKeyState(vbKeyControl) < 0 And GetAsyncKeyState(vbKeyV) < 0 Then
If KeysInUse = False Then
KeysInUse = True
Debug.Print "Control+V Pressed"
' Call Your Sub/Function here
Exit Sub
End If
Else
KeysInUse = False
End If
End Sub
i think this code best than hot keys codes thx
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
|