Results 1 to 10 of 10

Thread: [RESOLVED]Shortcut Keys

  1. #1

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475

    [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

  2. #2
    Addicted Member
    Join Date
    Mar 2003
    Posts
    206
    Module:
    VB Code:
    1. Public Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Long) As Integer
    2. Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
    3. Public Const PROCESS_ALL_ACCESS = &H1F0FFF

    Form:
    VB Code:
    1. If GetKeyPress(vbKeyF1) Then
    2. Command1_Click
    3. End If
    Might work. Not sure. If it doesn't, just search these forums for like "shortcut keys".

  3. #3

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475
    Nope didnt work. Thanks anyway though.
    If my post was helpful please rate it

  4. #4

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475
    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

  5. #5

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475
    I figured this out.
    If my post was helpful please rate it

  6. #6
    Addicted Member
    Join Date
    May 2004
    Location
    China
    Posts
    228
    Post why for others, and change the thread title to include resolved.
    You know the best way to find the answer to your question? SEARCH!
    www.google.com
    www.planet-source-code.com
    www.msdn.com
    http://www.vbforums.com/search.php?s=
    P.S. Its faster than waiting for replies too!

    [vbcode]
    If InStr(1, Message, "FIX MY CODE") <> 0 Then Reply = False
    If AnswerIn(Google, VB_Forums, PSC, MSDN) = True Then Reply = False
    [/vbcode]

  7. #7

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475
    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

  8. #8
    Lively Member
    Join Date
    May 2004
    Posts
    81
    VB Code:
    1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = 13 Then
    3.         'whatever code you want
    4.     End If
    5. End Sub

    is that what you mean? that will execute only if the program has focus and the combo box has focus.

  9. #9
    Lively Member
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    101
    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.
    Rave or die.

  10. #10

    Thread Starter
    Hyperactive Member wiccaan's Avatar
    Join Date
    Apr 2004
    Location
    127.0.0.1
    Posts
    475
    Originally posted by StuartC
    VB Code:
    1. Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = 13 Then
    3.         'whatever code you want
    4.     End If
    5. 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
  •  



Click Here to Expand Forum to Full Width