473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to implement listener for F7 key

I have an application that I want to run in the background until F7 key is
pressed. Does anyone know how to implement a listener for F7 keypress to
activate application?
Nov 17 '05 #1
2 6867
Hello Roger,
I have an application that I want to run in the background until F7 key is
pressed. Does anyone know how to implement a listener for F7 keypress to
activate application?


This can be made with a global system (keyboard) hook:

[Global System Hooks in .NET]
http://www.codeproject.com/csharp/GlobalSystemHook.asp

[Windows Hooks in the .NET Framework]
http://msdn.microsoft.com/msdnmag/is...0/CuttingEdge/

[Using Windows Hooks to Enhance MessageBox in .NET]
http://msdn.microsoft.com/msdnmag/is...1/CuttingEdge/
ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET
Nov 17 '05 #2


Roger wrote:
I have an application that I want to run in the background until F7 key is
pressed. Does anyone know how to implement a listener for F7 keypress to
activate application?


win32 api has a RegisterHotKey, to listen for CTRL+ALT+SHIFT+D:

internal class Win32
{
[DllImport("user32.dll", SetLastError=true)]
public static extern bool RegisterHotKey(IntPtr hWnd, int
hotkeyId, KeyModifiers fsModifiers, Keys vk);
[DllImport("user32.dll", SetLastError=true)]
public static extern bool UnregisterHotKey(IntPtr hWnd, int hotkeyId);
[Flags()]
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
}

public class SomeForm {
...
protected int hotkeyid = SOME_INTEGER_ID;
protected bool hotkey_registered;
SomeForm()
{
hotkey_registered = Win32.RegisterHotKey(Handle, hotkeyid,
Win32.KeyModifiers.Control | Win32.KeyModifiers.Alt |
Win32.KeyModifiers.Shift, Keys.D);
}
protected override void Dispose( bool disposing ) {
if ( hotkey_registered )
Win32.UnregisterHotKey(Handle, hotkeyid);
...
}

protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
switch(m.Msg)
{
case WM_HOTKEY:
hotkeyPressed(ref m);
break;
}
base.WndProc(ref m );
}
public void hotkeyPressed(ref Message m) { ... }
}

In the docs for RegisterHotKey the following is said of hotkeyid:

"[in] Specifies the identifier of the hot key. No other hot key in the
calling thread should have the same identifier. An application must
specify a value in the range 0x0000 through 0xBFFF. A shared
dynamic-link library (DLL) must specify a value in the range 0xC000
through 0xFFFF (the range returned by the GlobalAddAtom function). To
avoid conflicts with hot-key identifiers defined by other shared DLLs, a
DLL should use the GlobalAddAtom function to obtain the hot-key
identifier. "

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cherrish Vaidiyan | last post by:
Hello all, A warm Xmas greetings to all. I have a small problem with starting up the database. Here my strategy. I have installed Oracle 9i R 2 on Red Hat 9. i created two database on this...
1
by: Cherrish Vaidiyan | last post by:
sir, I have a small error in Listener configuration.I have two system with a database in each. I am using Red Hat 9 and Oracle 9i. so i shall anme the database and system. system 1 - node2 ...
5
by: Axel Dachtler | last post by:
Hi, I have a listener problem. The listener cannot read SERVICE_NAME in TNS-Descriptor. The service-name I specified in Oracle Net Manager for this database is testdb as well. ...
3
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work...
3
by: Roger Helliwell | last post by:
Hey guys, Subject line says it all. I have many presentation layer objects that need to be notified when a specific business-tier class has been modified. Thanks, Roger
6
by: Steve Teeples | last post by:
I have been perplexed by how to best treat an event that spans different classes. For example, I have a form which a user inputs data. I want to broadcast that data via an event to another...
4
by: Sai | last post by:
Friends, Like to implement soap listener using C#.net, Can any one shed some light on how to do this. Thanks, K
5
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point,...
1
by: michael ngong | last post by:
michael.john@gmx.at (Michael John) wrote in message news:<90cc4edd.0306230900.28075193@posting.google.com>... MIchael I you stated the OS and platform that could make it easier to address your...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.