It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

How to set a keyboard shortcut?

Moderator: dafunkymunky

How to set a keyboard shortcut?

Postby srk999 on Wed Aug 20, 2008 11:53 pm

How can I set a keyboard shortcut, such as- Alt + F1, that performs the same function as a particular button?

For example, I want to close a window and I have coded the button for it already. How can I make a keyboard shortcut so that pressing Alt + F1 closes the window.
srk999
 
Posts: 0
Joined: Wed Aug 20, 2008 10:50 pm

Postby chubzyko on Thu Aug 21, 2008 8:40 pm

try this codes.

Code: Select all
'// I have a timer named Timer1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName 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
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Const WM_CLOSE = &H10
Private Function KeyDown(ByVal vKey As KeyCodeConstants) As Boolean
KeyDown = GetAsyncKeyState(vKey)
End Function
Private Sub Timer1_Timer()
HotKey = vbKeyF1 '// Change this to desired hotkey
If KeyDown(HotKey) = True Then
iBox = InputBox("Process name?") '// Exact window name
hWnd1 = FindWindow(vbNullString, iBox)
SendMessage hWnd1, WM_CLOSE, 0, 0
End If
End Sub
"Failure is the key to success, so try and try until you succeed."
User avatar
chubzyko
100+ Club
 
Posts: 104
Joined: Wed Jul 30, 2008 10:48 pm
Location: Marikina City, Philippines


Who is online

Users browsing this forum: No registered users and 10 guests