|
-
Jun 4th, 2004, 08:02 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Shortcut Keys
Hey guys, just wanted to know how I could add a shortcut key for a button. Like when you press CTRL + 1 it would press the button. I need this to work if the program is minimized to the tray also. Thanks in advance.
-Wiccaan
Last edited by wiccaan; Jun 5th, 2004 at 11:12 PM.
If my post was helpful please rate it 
-
Jun 4th, 2004, 08:23 PM
#2
Addicted Member
Module:
VB Code:
Public Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Form:
VB Code:
If GetKeyPress(vbKeyF1) Then
Command1_Click
End If
Might work. Not sure. If it doesn't, just search these forums for like "shortcut keys".
-
Jun 4th, 2004, 08:51 PM
#3
Thread Starter
Hyperactive Member
Nope didnt work. Thanks anyway though.
If my post was helpful please rate it 
-
Jun 4th, 2004, 09:34 PM
#4
Thread Starter
Hyperactive Member
Ok I got this part of the code to work. But it only works when the Visual Basic window is the one that your looking at meaning the focus is on it. I need it to be able to be used if you have another window focused on becuase it writes to that window.
The program is a game and this vb app Im making is a trainer. The game runs in full screen because a friend of mine cant run it in windowed mode. So he wanted me to try to make a trainer that he can use while he is playing the game.
Thanks to anyone that can help. This is the code that I use so far in this project.
Form:
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF4 Then
Call WriteAInt(&H6FCAB0, &HB)
Call WriteAInt(&H78F5A4, &HB)
End If
End Sub
Module:
Code:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Sub WriteAInt(Address As Long, Value As Long)
Dim hwnd As Long, pid As Long, phandle As Long
'PSO for PC is the window name
hwnd = FindWindow(vbNullString, "PSO for PC")
If (hwnd <> 0) Then
GetWindowThreadProcessId hwnd, pid
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (phandle <> 0) Then
WriteProcessMemory phandle, Address, Value, 4, 0&
End If
CloseHandle phandle
End If
End Sub
If my post was helpful please rate it 
-
Jun 5th, 2004, 02:38 AM
#5
Thread Starter
Hyperactive Member
If my post was helpful please rate it 
-
Jun 5th, 2004, 03:10 AM
#6
Addicted Member
Post why for others, and change the thread title to include resolved.
-
Jun 5th, 2004, 08:11 PM
#7
Thread Starter
Hyperactive Member
Ok to do this just use this in a module:
Code:
Public Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
And put this in a timer for what you want it to do:
Code:
If GetAsyncKeyState("KEYNUMBER_HERE") Then
WHAT YOU WANT IT TO DO HERE
End If
Ok now I need some help again with this same thing.
I made that program and it works great.
Now Im making a web browser thing for a friend. I need to know how to make it so when you type in the Combo box, the url, and hit enter it will go, but only when your in typing in the combo box. The why I figured it out makes it so that if you hit enter anywhere even while the program is minimized it goes to the url you typed. I need to fix that.
Anyone know how to do this?
Thanks in advance.
PS This is what Im using for the timer right now:
Code:
Private Sub Timer1_Timer()
If GetAsyncKeyState("13") Then
Browser.Navigate cmbURL.Text
End If
End Sub
It works just not the way I want it to.
If my post was helpful please rate it 
-
Jun 5th, 2004, 09:40 PM
#8
Lively Member
VB Code:
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
'whatever code you want
End If
End Sub
is that what you mean? that will execute only if the program has focus and the combo box has focus.
-
Jun 5th, 2004, 09:56 PM
#9
Lively Member
ok. the best way to make something happen while your program is in the system tray is to register a hotkey. If you want to know how to do that..... let me know, I'll be getting a sample project ready.......and if you're satisfied with how you worked it out, that's cool too.
I'll prolly post the project anyway.
-
Jun 5th, 2004, 11:12 PM
#10
Thread Starter
Hyperactive Member
Originally posted by StuartC
VB Code:
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
'whatever code you want
End If
End Sub
is that what you mean? that will execute only if the program has focus and the combo box has focus.
Thanks that worked perfectly.
If my post was helpful please rate it 
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
|