469,358 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

Assign a hot key to an application

Hai all,
I have created an application which is something like a trouble
shooter. I want to use the F12 key. When the is user is using some
other application say Internet Explorer and if he presses F12 then my
application should pop up. I made a registry entry so that my
application starts when the user logs in. and I have a sys tray icon
for my application. but I can get the F12 key press. I works only when
some form of that particular application is active.

Can any body help me out.

Thank you all in advance.

S.ArulPrakash
Jul 17 '05 #1
5 7260
On 2 Jan 2004 02:18:42 -0800, sa**********@rediffmail.com
(ArulPrakash) wrote:
Hai all,
I have created an application which is something like a trouble
shooter. I want to use the F12 key. When the is user is using some
other application say Internet Explorer and if he presses F12 then my
application should pop up. I made a registry entry so that my
application starts when the user logs in. and I have a sys tray icon
for my application. but I can get the F12 key press. I works only when
some form of that particular application is active.

Can any body help me out.


You need to look at RegisterHotKey

There is an example in the downloadable API Guide from

www.AllAPI.net
Jul 17 '05 #2
thank you J French. It worked out. I thought of hooking the keyboard
and all that complex stuffs.

Thank You.
ArulPrakash.S
er*****@nowhere.com (J French) wrote in message news:<3f***************@news.btclick.com>...
On 2 Jan 2004 02:18:42 -0800, sa**********@rediffmail.com
(ArulPrakash) wrote:
Hai all,
I have created an application which is something like a trouble
shooter. I want to use the F12 key. When the is user is using some
other application say Internet Explorer and if he presses F12 then my
application should pop up. I made a registry entry so that my
application starts when the user logs in. and I have a sys tray icon
for my application. but I can get the F12 key press. I works only when
some form of that particular application is active.

Can any body help me out.


You need to look at RegisterHotKey

There is an example in the downloadable API Guide from

www.AllAPI.net

Jul 17 '05 #3
On 3 Jan 2004 01:24:07 -0800, sa**********@rediffmail.com
(ArulPrakash) wrote:
thank you J French. It worked out. I thought of hooking the keyboard
and all that complex stuffs.


Not just complex - also rather dangerous

Out of curiousity, how did you intercept the WM_HOTKEY message ?
- sub-classing or like KPD's interesting method
Jul 17 '05 #4
er*****@nowhere.com (J French) wrote in message news:<3f***************@news.btclick.com>...
On 3 Jan 2004 01:24:07 -0800, sa**********@rediffmail.com
(ArulPrakash) wrote:
thank you J French. It worked out. I thought of hooking the keyboard
and all that complex stuffs.


Not just complex - also rather dangerous

Out of curiousity, how did you intercept the WM_HOTKEY message ?
- sub-classing or like KPD's interesting method


I just copied the example from KPD given and modified the key
combination to match my requirement.

But I already completed the exercise by hooking the keyboard and
tracing each and every key pressed onto a text box. I will get all the
keypress actions i a text box and check for my hot key. that too
worked out.

here is the window procedure i have return with hooking the keyboard:
Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long,
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim RetVal As Long
Dim KeyAscii As Long
Dim KeyName As String

If Msg = WM_USER Then
If (lParam And &H80000000) = 0 Then
If GetKeyboardState(KeyboardState(0)) <> 0 Then
RetVal = ToAscii(wParam, lParam, KeyboardState(0),
KeyAscii, 0)
If (RetVal = 1) And ((KeyAscii > 31) Or (KeyAscii = 13))
Then

If KeyAscii = 13 Then
Form1.Text1.Text = Form1.Text1.Text & "{ENTER}"
Else
Form1.Text1.Text = Form1.Text1.Text &
Chr(KeyAscii)
End If
Else
KeyName = String(20, " ")
RetVal = GetKeyNameText(lParam, KeyName, 20)
If RetVal <> 0 Then
KeyName = Left(KeyName, RetVal)
Form1.Text1.Text = Form1.Text1.Text & "{" &
KeyName & "}"
End If
End If
End If
Else

End If
End If
If (GetKeyState(VK_SHIFT) And &HF0000000) And
(GetKeyState(VK_CONTROL) And &HF0000000) And (GetKeyState(VK_F12) And
&HF0000000) Then

Form1.Combo1.Text = Form1.Combo1.List(0)
Form1.Show

End If
WindowProc = CallWindowProc(PrevFuncPointer, hwnd, Msg, wParam,
lParam)
Exit Function
End Function

I made use of the API function "SetWindowsHookEx" and
"UnhookWindowsHookEx" and created a dll and used it in the exe. but i
had a problem that i have to register this exe in each and every
machine in the network and so on so i searched for another method to
assign hot key.

Any way thanks again J French.
Jul 17 '05 #5
On 5 Jan 2004 00:52:03 -0800, sa**********@rediffmail.com
(ArulPrakash) wrote:

<snip>

I made use of the API function "SetWindowsHookEx" and
"UnhookWindowsHookEx" and created a dll and used it in the exe. but i
had a problem that i have to register this exe in each and every
machine in the network and so on so i searched for another method to
assign hot key.


That is very interesting - an AX DLL seems to have done the trick
- I've only managed that with Delphi DLLs

I agree totally that the HotKey method is cleaner
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

33 posts views Thread by aa | last post: by
1 post views Thread by gaffar | last post: by
reply views Thread by dudinissan | last post: by
5 posts views Thread by J-T | last post: by
7 posts views Thread by Joe | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.