Catching global keystrokes

Hello. I need my program to react to some key combination no matter if 
the program's window is active or not. How can this be done?
0
11/7/2008 6:42:52 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
765 Views

Similar Articles

[PageSpeed] 9

Depends on the details of the key combinations as to what you have to do, precisely, but a
WH_GETMESSAGE hook looking for WM_KEYDOWN, WM_SYSKEYDOWN or WM_CHAR is a start.

Note if the key combination is Ctrl+Alt+Del, then it will never be possible.

In Vista, you will not be able to get ALL keystrokes unless you are running as
administrator.

See my essay on hooks on my MVP Tips site.
				joe

On Fri, 07 Nov 2008 09:42:52 +0300, Vladimir <thamiorsinister@gmail.com> wrote:

>Hello. I need my program to react to some key combination no matter if 
>the program's window is active or not. How can this be done?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
11/7/2008 6:52:03 AM
This involves a system-wide message hook. Look into SetWindowsHookEx.

-- 
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Vladimir" <thamiorsinister@gmail.com> wrote in message 
news:gf0o1e$pk7$1@aioe.org...
> Hello. I need my program to react to some key combination no matter if the 
> program's window is active or not. How can this be done? 

0
jwood (1291)
11/7/2008 6:56:31 AM
On Nov 7, 1:42=A0am, Vladimir <thamiorsinis...@gmail.com> wrote:
> Hello. I need my program to react to some key combination no matter if
> the program's window is active or not. How can this be done?

You need a system wide hook to do this. The code will go in a DLL. You
want to make sure you dont use MFC for the hook as it gets loaded in
all processes; at least be aware of it.

--
Ajay
0
ajaykalra (6842)
11/7/2008 6:41:48 PM
"Vladimir" <thamiorsinister@gmail.com> wrote in message
news:gf0o1e$pk7$1@aioe.org...
> Hello. I need my program to react to some key combination no matter if the
> program's window is active or not. How can this be done?

In addition to a global keyboard hook, you can also use Raw Input.  But both 
techniques don't return you keystrokes in elevated processes on Vista, if 
your app is not elevated itself.  This, like so many other hinderances, is 
in the name of security.

-- David 

0
dc2983 (3206)
11/7/2008 10:19:55 PM
> Hello. I need my program to react to some key combination no matter if 
> the program's window is active or not. How can this be done?

Everybody mentioned hooking.
But if all you want to do is to react to some kind of accelerator
combination, you can just use RegisterHotKey.
Way easier to use than hooking (and less invasive for the system)



-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
11/8/2008 5:00:05 AM
Reply:

Similar Artilces:

URGENT: Cannot setup new outlook profiles because Global Address List is not reachable
Hi everybody! We have a very great trouble!! Please, help us We have two servers - Server1: Windows 2K SP3 is a Domain Controller and Global Catalog for DOMAI - Server2: Windows 2K SP3 is a Server of DOMAIN (not a DC) and it is running Exchange 2000 SP All of then up and running with no problems UNTIL.. After a very odd crash, we had to demote and promote Server1 from being the GC. OK But, then... we have realized that from the view of point of Outllook clients the Global Address List was empty We are not able to access Global Adress List from the Exchange Manager. When we are navi...

Catch WM_SIZE
Hi, How to catch the WM_SIZE message of a control created dynamically. I mean : BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); // m_MyControl derived from CWND m_MyControl.Create( NULL, _T(""), WS_VISIBLE, CRect(10, 10, 0, 0), this, 1 ); } LRESULT CMyDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_SIZE : // Catch this message but when it is m_MyControl that is resizing. } } Regards, "Erakis" <Erakis@discussions.microsoft.com> wrote in message news:5BC2F5F0-D19B-4B3E-9881-E...

global list #2
The US office of my company has exchange 2003 and the German office has Lotus Notes. Is there a way to get the German employess email information into my exchange servers global access list? can distribution lists be created in the golbal address list? ...

global search addon for GP and/or SBF?
I am looking for a global transaction lookup addon for GP. I am familiar with smartlists & Rockton Software's smartfill. These are great but do not fill what i'm looking for. What i am looking for is something where I can type in criteria such as doc amount, doc date, vend/cust id and system (or several of these at the same time) and the system will find the tranaction no matter wether it is a ar invoice, ar payment, gl trx, ap trans or whatever. In other words a central lookup. It seems that in gp one needs find just the write search and ask just the write question to fi...

Catch all email account
is there a way to set up a catch all email account with exchange 2003. Yes i know the implicaitons of doing this but i believe it is the only way to get this person to realize it is not a good idea after a day or two. In news:uu4FR3XHHHA.924@TK2MSFTNGP02.phx.gbl, Andrew Mallette <andrewm270@aol.com> typed: > is there a way to set up a catch all email account with exchange 2003. > Yes i know the implicaitons of doing this but i believe it is the only > way to get this person to realize it is not a good idea after a day > or two. Check out MailBasket at www.turbogeeks.com. ...

Global Signature Line
How can I assign a global signature line to all my outlook users (possilby from within Exchange 2007)? Is there a way to control this and assign to all users? See http://www.howto-outlook.com/howto/corporatesignatures.htm -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World Answers ----- "dswindell" <dswindell@discussions.microsoft.com> wrote in message news:CEBCEA34-6880-44D2-8A82-4A9AB5DF...

how to catch key stroke events "globally"
How do can one catch key pressed events "globally"? By that, I don't mean by the main app, I mean, say for example you want to create a "panic button". So that say you're running what ever app (not the one you made), and you want to catch/use the escape key as your panic button. The user presses the escape key, and all windows become hidden. The first problem, is catching the escape key, the second is iterating all top level apps/windows. "Martin Ortiz" <martinortiz@optonline.com> skrev i en meddelelse news:u6eERqJ8DHA.488@TK2MSFTNGP12.phx.gbl... ...

Catching mail for disable user with no mailbox
I have a user ("olduser') in AD who has been gone for a year and never had an Exchange mailbox (pre-migration). As of today, I want to have any inbound mail to "olduser" captured by the SMTP virtual server and sent to another user. I simply gave "otheruser" an additional address of "olduser@domain" and delivery works internally via Exchange, but external senders get a reply: Remote host said: 550 5.7.1 Requested action not taken: mailbox not available. I expect I could delete the old user from AD, but that's not permitted right now. Thanks...

Customise Global Address List Column
I would like to include a "Designation" column in the GAL. Can this be done in MS Exchange 2003? Hello: Yes, it can be done. I don't see it discussed much, but there are articles out there. You'll need to customize the Details Templates. You should be able to add any indexed (replicated by GCs) attribute to the GAL. I don't know if non-indexed attributes would work properly in a multi-domain AD. One company I worked for used this to expose the employee ID number, which was in one of the custom attributes. Start here: http://blogs.msdn.com/dgoldma...

Global statements on footer of all emails
Does anyone know how to place a message on the footer of emails globally? I am looking for a way to place the following message: "This electronic message is privileged and confidential material. This message is intended solely for the individual or entity named above. If the receiver of this message is not the intended recipient, please be advised that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately and delete it. Thank you." On everyones mai...

catching VK_SPACE in a CHotkeyCtrl
hi all, when i create a CHotKeyCtrl ( even in a new and empty project in an empty dialog) i cannot catch any VK_SPACE key combination, eg if i press Ctrl+Space the hotkey control immediately shows "None" instead. Also the "Del" key cannot be handled. any ideas Peter ...

What am I catching?
I've got a piece of code, looks something like this : try { savetheworld(); } catch(CException* pe) { telltheuser(); } catch(...) { panic(); } The only thing I ever throw are CExceptions (or classes derived from CExceptions), I've even done _set_se_translator() so I capture C structured exceptions (like our good friend 0xC0000005) and turn then into CExceptions that I throw. And yes, they are pointers to CException objects that I've new'ed up, not the objects themselves. So why is it, every once in a while, I catch something that isn't a CException? Now I realize that&...

Recover newsgroup from catching up
I've got a newsgroup where I used the Catch Up option. I now find myself interested in retrieving the messages that were dropped in doing so. How can I completely reset the newsgroup? -- David Trimboli http://www.trimboli.name/ While in the newsgroup: View | Current View. Make sure Show All Messages and Group Messages By Conversation are checked. Tools | Options | Read. Uncheck: Get XXX headers at a time. Right click on the newsgroup in the Folder Tree | Properties | Local File | Reset. Switch to another folder and then back and all available messages will be dow...

XP users cannot logon using their Domain catched account
Hi All, Workstations (mostly laptops) in my organization have been having problems logging on to the domain when the network is unplugged.Previously they have been logging on without any issues. This started recently. I have checked the interactive Logon Policy for caching for the domain and its set to 1. Mojority of the users are used to working offline while logged on to the domain. Can anyone put me through on how to resolve this ASAP.Thanks. We run a Windows Server 2003 SP1 based network. -- Buchi This is the wrong Newsgroup try Windows Admin. But there is a limit to the number ...

else or catch
Have the following for inserting a person's name. If the user was to select the empty space of the droplist, it will error. I was wondering if an else or the full try...catch would be needed here? If an else is sufficient, what is the better approach in what to use. protected void lvwDetailDeveloperEditInsert_ItemInserting(object sender, ListViewInsertEventArgs e) { DropDownList ddlDeveloperIDInsertEdit = (DropDownList)e.Item.FindControl("ddlDeveloperIDInsertEdit"); Label ChangeRequestIDLabel = (Label)e.Item.FindControl("ddlSelect...

Global Customer Account Number
Is there any special character that cannot be used in the field for Global Customer Account Number? For example, TH0001`? Thanks. single quotes are always dangerous, but Account Number is a varchar field - any alphanumeric values are valid. -- Glenn Adams Tiber Creek Consulting http://www.tibercreek.com glenn@tibercreek.com ---------------------------------------------- Please DO NOT respond to me directly but post all responses here in the newsgroup so that all can share the information "Raymond Cheok" <raymondcheok@fareastflora.com> wrote in message news:BF420D72.15...

try/catch, return from catch ?
Is this baaad? try { m_Database.OpenEx( sDSN ); return TRUE; } catch( CDBException* pxE ) { pxE->Delete(); return FALSE; } or MUST I exist the try/catch clause first before returning to allow some kind of clean up? e.g. BOOL bFail = FALSE; try { m_Database.OpenEx( sDSN ); } catch( CDBException* pxE ) { pxE->Delete(); bFail = TRUE; } return !bFail; Lisa The second method is better method. It will allow cleanup tooo if required. But i think it is not a good idea to write code which includes negations as it can be written without that. In the second c...

How to catch keydown
I have CIpAddressCtrl placed in CListCtrl subitem. I need to catch keydown pressing in CIpAddressCtrl, only way which I know is in PreTranslateMessage(). But I have problems to call some functions from PreTranslateMessage(). Does exist other way how to catch "up" keystroke in CIpAddressCtrl ? Thx, Peter Would OnKeyDown() or OnKeyUp() work for you: http://msdn2.microsoft.com/en-us/library/983st27a(VS.80).aspx http://msdn2.microsoft.com/en-us/library/yddt1ty6(VS.80).aspx Tom "Peter" <Peter@discussions.microsoft.com> wrote in message news:A9F2EABB-3005-47A7-BEB...

Global template normal on closing Outlook
Can anyone tell me how to fix an error I get when I close MS Outlook. It asks if I want to save changes and if I click on yes it won't close and asks again. The statement is "Save changes to Global template normal". Sounds like you are using Word as your e-mailk editor. In Word you want to uncheck "Prompt before ssaving normal template". In Office 2007 - Word Options | Advanced. "Pat" wrote: > Can anyone tell me how to fix an error I get when I close MS Outlook. It asks > if I want to save changes and if I click on yes it won't c...

Set up a global address book in a company with 2 exchange servers
Hi, i have the following situation: my company has 2 separate locations with both their own SB Server2000 and Exchange Server2000. The 2 locations are within the same domain and collaborate via VPN. As each location has its own Act.Dir. they do NOT share users, and they subsequently do NOT share the Global Standard Address Book. How can I achieve having an address book containing all users from BOTH locations? Thanks in advance Upgrade to 2003 and go with Identity Integration Feature Pack. This will allow you sync GALs. Another option would be MIIS but that is overkill for your scen...

Global Variables to assign Recipient Policies
Is there a way to assign email addresses using windows account variables? for example, I want to create a new address for every user (using the receipient policy service) with the first name of the user (%firstname%) + "." + last name (%lastname%) of the user @domain.com? I'm not sure what the variables names are, if this is possible. Thanks! %g.%s http://support.microsoft.com/?kbid=285136 -- Bharat Suneja MCSE, MCT www.zenprise.com blog: www.suneja.com/blog ----------------------------------------- "Scott" <Scott@discussions.microsoft.com> wrote in mes...

Catching window move
Hello, I have created a sample dialog based MFC application. I wanted to make it unable to move the dialog window. For that in that dialog calss the have defined PreTranslateMessage() to catch WM_MOVE or WM_MOVING, but when i run the apllication and move the dialog by puttin g focus on title bar, these messages are not fired by windows. what should i need to do to disable dialog(with titlebar) move? Regards, Manohar Handle WM_NCHITTEST. -- ====== Arman "Manu" wrote: > Hello, > I have created a sample dialog based MFC application. I > ...

try/catch vs TRY/CATCH
Hi, What is in your opinion the preferred way of doing exception handling for MFC objects (such as the CFile)... the try/catch mechanism or the MFC based TRY/CATCH macros? Thanks Adeel Use try/catch. I don't recall what TRY/CATCH does but, basically, that was provided before VC++ had full support fro try/catch. -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com "Adeel" <dontWantSpam@All> wrote in message news:ORLqQz3fGHA.4568@TK2MSFTNGP03.phx.gbl... > Hi, > > What is in your opinion the preferred way of doing exception handling for ...

Global Calendar Notificiations
I have set up a global calendar; Microsoft Exchange; Outlook 2007. When I enter an event with a Notification/Alarm the notification does not pop up for any of the other users with access to the calendar. Is there any way to do this? -- Thank you. D. E. Comeau, PMP No, reminders only fire from the default mailbox. you could try reminder manager - http://www.slovaktech.com -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscrib...

Global Security Policy for Signatures
Is there such a thing as a Global Security Policy or something similar for Outlook Signatures? I work for an accounting firm and I've been asked to look into setting up a firm wide signature for our tax people only. Any clues on how I can get this done? Does Microsoft provide a way to do this or am I looking at a 3rd party app? If you want it to be mandatory, you are looking at either an Exchange = event sink or a third-party application. See = http://www.slipstick.com/addins/content_control.htm=20 --=20 Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 ...