PC Review


Reply
Thread Tools Rate Thread

Capturing Global Function Key Press

 
 
Alex Maghen
Guest
Posts: n/a
 
      15th Feb 2009
Hi. I need to set a Global Key Hook to capture the keypress of function keys
(F9, F10, etc., etc.). I've been using a sample recommended to me here
("userActivityHook"), but my "KeyPress()" event handler does not get called
for Function Keys.

How is this done?

Thanks.

Alex
 
Reply With Quote
 
 
 
 
Zhi-Xin Ye [MSFT]
Guest
Posts: n/a
 
      16th Feb 2009
Hi Alex,

Thank you for using Microsoft Managed Newsgroup Service, I'm Zhi-Xin Ye,
it's my pleasure to work with you on this issue.

Using the keyword "userActivityHook" I find the sample you mentioned on
CodeProject.

In the HookManager.Callbacks.cs file, there's a method named
KeyboardHookProc:

private static int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
......
if (s_KeyPress != null && wParam == WM_KEYDOWN)
{
//......

if (ToAscii(MyKeyboardHookStruct.VirtualKeyCode,
MyKeyboardHookStruct.ScanCode,
keyState,
inBuffer,
MyKeyboardHookStruct.Flags) == 1)
{
.....
s_KeyPress.Invoke(null, e);
}
}

If you set a breakpoint at the line which calls the ToAscii API and debug
the program, you'll find that when a function key is pressed, the return
value of the ToAscii API is not 1, so it does not run to the line "
s_KeyPress.Invoke(null, e); ", so the KeyPress event does not fire. You
can change the code to fire the KeyPress event as you needed, but it's not
recommended to do so, it make no sense to fire KeyPress event for
noncharacter keys. Instead, you can handle the KeyDown or KeyUp event for
the function keys(noncharacter keys).

If you have any question or concern, please feel free to let me know. I
will be happy of assistance.

Have a nice day!

Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing key press messages Jeremy Microsoft Dot NET Framework Forms 1 27th Oct 2008 12:00 PM
Capturing Enter key press inconsistent behaviour andy.cotgreave@gmail.com Microsoft Access Forms 1 14th Jul 2006 05:19 PM
Capturing the TAB key press in the DataGrid =?Utf-8?B?VmVudUdvcGFs?= Microsoft C# .NET 0 19th Apr 2005 01:01 PM
Capturing a TAB key press event supster Microsoft C# .NET 7 29th Mar 2005 02:36 AM
frezes at setup will now install windows-press enter to continue/press R to repa Ric Windows XP Setup 0 15th Oct 2003 06:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 PM.