CodeItBetter Programming Another VB Programming Blog

How to set system wide hotkey to open an application

Posted on June 30, 2010

I was looking for a simple solution to open calculator whenever I click a shortcut key. There are many ways to do that. I don't want to spend more time on this project, as I am the only person going to use it. So created a simple application using GetAsyncKeyState API. Here is the code for you to try:

Instructions:

  • Create a new Project
  • Add a new Form to it and name it as Form1
  • Add a new timer control to it and name it as tmrTicker

Now, add the following code to Form1:

1
2
3
4
5
6
7
8
9
10
11
12
13
Option Explicit
 
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
 
Private Sub tmrTicker_Timer()
    If GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyQ) Then
        Call Shell("C:\WINDOWS\system32\calc.exe", vbNormalFocus)
    End If
End Sub
 
Private Sub Form_Load()
    Me.Hide
End Sub

Create the exe file and add it to windows startup. Now, whenever you click Ctrl + Q, the calculator will be opened. In this way you can open-up any application you want.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

Trackbacks are disabled.