Click here to Skip to main content
11,721,053 members (78,901 online)

Windows API

 
AnswerRe: startprocess Pin
Luc Pattyn15-Jun-12 21:25
mvpLuc Pattyn15-Jun-12 21:25 
Questionsubitem select & edit Pin
Dmitri Novikov12-May-12 10:38
memberDmitri Novikov12-May-12 10:38 
AnswerRe: subitem select & edit Pin
Richard MacCutchan12-May-12 21:43
mvpRichard MacCutchan12-May-12 21:43 
GeneralRe: subitem select & edit Pin
Dmitri Novikov13-May-12 0:11
memberDmitri Novikov13-May-12 0:11 
QuestionHow to write a Windows terminal server Pin
GS_windows10-May-12 0:00
memberGS_windows10-May-12 0:00 
AnswerRe: How to write a Windows terminal server Pin
Richard MacCutchan10-May-12 0:40
mvpRichard MacCutchan10-May-12 0:40 
AnswerRe: How to write a Windows terminal server Pin
Bernhard Hiller10-May-12 4:19
memberBernhard Hiller10-May-12 4:19 
QuestionEvent Log and RenderingInfo in a Spanish environment Pin
Kevin Derhak27-Mar-12 4:26
memberKevin Derhak27-Mar-12 4:26 
QuestionRegConnectRegistry : Access Denied Pin
san8022-Feb-12 23:43
membersan8022-Feb-12 23:43 
AnswerRe: RegConnectRegistry : Access Denied Pin
Pete O'Hanlon22-Feb-12 23:47
protectorPete O'Hanlon22-Feb-12 23:47 
GeneralRe: RegConnectRegistry : Access Denied Pin
san8023-Feb-12 3:09
membersan8023-Feb-12 3:09 
GeneralRe: RegConnectRegistry : Access Denied Pin
Pete O'Hanlon23-Feb-12 3:59
protectorPete O'Hanlon23-Feb-12 3:59 
GeneralRe: RegConnectRegistry : Access Denied Pin
san8024-Feb-12 1:31
membersan8024-Feb-12 1:31 
QuestionSendInput() does not work after GetMessage() Pin
sashok_bg9-Feb-12 2:46
membersashok_bg9-Feb-12 2:46 
Hello everyone,

I was trying to make an application, that registers a hotkey and when the hotkey is pressed, simulates a keyboard event or mouse click.

To do so, I have chosen to use the RegisterHotkey(), SendInput() and GetMessage() windows functions.

The problem is that as soon as I declare a call to GetMessage() - SendInput() stops working.

In the code below, I made an experiment - the program is waiting for 3 seconds (to give me some time) and as soon as I start it, I bring notepad to focus and the "KeyDown(97)" types "1" in the notepad window.

However, this behavior does not work when the MessageLoop() is entered.

Thank you for your help.

Best Regards,

Alex

#define _WIN32_WINNT 0x0500
 
#include "stdafx.h"
#include <Windows.h>

 
//This function simulates a keyboard button press and release. Argument is VirtualKey
//This function works fine, before the GetMessage() function is declared/called
void KeyDown(int vk){
 
	printf("Called KeyDown with parameter %d \n",vk);
 
	INPUT	Input[1];
 
	Input[0].type  = INPUT_KEYBOARD;
	Input[0].ki.wVk= vk;
 
	printf("Sending Input\n");
	SendInput(1, Input, sizeof(Input));
}
 

//This function is blocking and waiting for a message to arrive
void MessageLoop(){
	MSG msg = {0};
	while (GetMessage(&msg, NULL, 0, 0) != 0)
    {
 
		//if the arrived message is a hotkey event
        if (msg.message == WM_HOTKEY)
        {
			//some debugging
			printf("msg.message %d, msg.lParam %d, msg.wParam %d \n",msg.message,msg.lParam,msg.wParam);
 
			//press the numeric '1' on the keyboard - doesn't work
			KeyDown(97);
        }
 
		TranslateMessage(&msg);
		DispatchMessage(&msg);
    }
}
 
int main(int argc, char* argv[])
{
 
	//This part works, only when the GetMessage() function is in a separate function ex: MessageLoop----
	Sleep(3000);
	KeyDown(97);
 
	//Register an ALT-CTR-A hotkey with ID - 1. First argument is NULL to make the hotkey global (it is a hWnd)
	RegisterHotKey(
		NULL,
		1,
		MOD_CONTROL | MOD_ALT,
		0x41
	);  //0x41 is 'a'

	//Enter the message loop that blocks and waits for a message to arrive for this application

	//Note that if I put the 'while (GetMessage(&msg, NULL, 0, 0) != 0)' code here, 
	//instead of putting it in a separate function, 
	//the 'KeyDown(97)' call on the 2nd line of the main() function will not work !
	MessageLoop();
 
	//clean up
	UnregisterHotKey(NULL,1);
 
	return 0;
}

AnswerRe: SendInput() does not work after GetMessage() Pin
Dhiraj Pallin18-Feb-12 16:25
memberDhiraj Pallin18-Feb-12 16:25 
GeneralRe: SendInput() does not work after GetMessage() Pin
sashok_bg20-Feb-12 21:30
membersashok_bg20-Feb-12 21:30 
AnswerRe: SendInput() does not work after GetMessage() Pin
JohnCz27-Apr-12 9:24
memberJohnCz27-Apr-12 9:24 
QuestionQuestion about (CX?) destructor? Pin
Super Lloyd24-Jan-12 4:19
memberSuper Lloyd24-Jan-12 4:19 
AnswerRe: Question about (CX?) destructor? Pin
Albert Holguin3-Feb-12 5:18
memberAlbert Holguin3-Feb-12 5:18 
AnswerRe: Question about (CX?) destructor? Pin
Aescleal14-Apr-12 21:22
memberAescleal14-Apr-12 21:22 
QuestionThe Metro Tile expands: and then ... what ? Pin
BillWoodruff13-Jan-12 0:35
memberBillWoodruff13-Jan-12 0:35 
AnswerRe: The Metro Tile expands: and then ... what ? Pin
Pete O'Hanlon13-Jan-12 0:56
protectorPete O'Hanlon13-Jan-12 0:56 
GeneralRe: The Metro Tile expands: and then ... what ? Pin
BillWoodruff13-Jan-12 6:07
memberBillWoodruff13-Jan-12 6:07 
AnswerRe: The Metro Tile expands: and then ... what ? Pin
Jeremy Hutchinson18-Jan-12 8:33
memberJeremy Hutchinson18-Jan-12 8:33 
GeneralRe: The Metro Tile expands: and then ... what ? Pin
BillWoodruff2-Feb-12 13:59
memberBillWoodruff2-Feb-12 13:59 
QuestionLoadLibrary error 127 on W7 X64 Pin
DusanDusan13-Nov-11 7:31
memberDusanDusan13-Nov-11 7:31 
AnswerRe: LoadLibrary error 127 on W7 X64 Pin
Richard Andrew x6419-Jan-12 9:46
memberRichard Andrew x6419-Jan-12 9:46 
GeneralRe: LoadLibrary error 127 on W7 X64 Pin
DusanDusan19-Jan-12 21:03
memberDusanDusan19-Jan-12 21:03 
QuestionMetro interaction with another application running in Win8 ? Pin
BillWoodruff16-Oct-11 18:10
memberBillWoodruff16-Oct-11 18:10 
AnswerRe: Metro interaction with another application running in Win8 ? Pin
Nishant Sivakumar17-Oct-11 5:16
mvpNishant Sivakumar17-Oct-11 5:16 
GeneralRe: Metro interaction with another application running in Win8 ? Pin
BillWoodruff17-Oct-11 15:21
memberBillWoodruff17-Oct-11 15:21 
AnswerRe: Metro interaction with another application running in Win8 ? Pin
Luc Pattyn17-Oct-11 16:23
mvpLuc Pattyn17-Oct-11 16:23 
GeneralRe: Metro interaction with another application running in Win8 ? Pin
BillWoodruff17-Oct-11 17:22
memberBillWoodruff17-Oct-11 17:22 
AnswerRe: Metro interaction with another application running in Win8 ? Pin
Luc Pattyn17-Oct-11 17:59
mvpLuc Pattyn17-Oct-11 17:59 
AnswerRe: Metro interaction with another application running in Win8 ? Pin
Pete O'Hanlon17-Oct-11 5:31
protectorPete O'Hanlon17-Oct-11 5:31 
GeneralRe: Metro interaction with another application running in Win8 ? Pin
BillWoodruff17-Oct-11 15:27
memberBillWoodruff17-Oct-11 15:27 
QuestionDialogBox - ProgressBar Problem Pin
bsaidus16-Oct-11 3:13
memberbsaidus16-Oct-11 3:13 
AnswerRe: DialogBox - ProgressBar Problem Pin
Albert Holguin16-Oct-11 18:18
memberAlbert Holguin16-Oct-11 18:18 
GeneralRe: DialogBox - ProgressBar Problem Pin
bsaidus16-Oct-11 22:14
memberbsaidus16-Oct-11 22:14 
GeneralRe: DialogBox - ProgressBar Problem Pin
Ravi Bhavnani19-Oct-11 7:02
memberRavi Bhavnani19-Oct-11 7:02 
QuestionWindows NameSpace Extension Pin
ycorre10-Oct-11 16:19
memberycorre10-Oct-11 16:19 
AnswerRe: Windows NameSpace Extension - Repost Pin
Richard MacCutchan10-Oct-11 22:21
mvpRichard MacCutchan10-Oct-11 22:21 
QuestionHow to Get To Metro Screen Pin
Richard Andrew x6424-Sep-11 11:22
memberRichard Andrew x6424-Sep-11 11:22 
AnswerRe: How to Get To Metro Screen Pin
Jeremy Hutchinson26-Sep-11 7:50
memberJeremy Hutchinson26-Sep-11 7:50 
GeneralRe: How to Get To Metro Screen Pin
Pete O'Hanlon26-Sep-11 8:05
protectorPete O'Hanlon26-Sep-11 8:05 
QuestionUAG: how to ‘embed’ into DCA? Pin
Member 26575215-Sep-11 23:41
memberMember 26575215-Sep-11 23:41 
QuestionCreateMetaFile on Win7 64bit Pin
Carsten Leue29-Aug-11 6:14
memberCarsten Leue29-Aug-11 6:14 
AnswerRe: CreateMetaFile on Win7 64bit Pin
Dave Kreskowiak29-Aug-11 8:18
mvpDave Kreskowiak29-Aug-11 8:18 
GeneralRe: CreateMetaFile on Win7 64bit Pin
Carsten Leue29-Aug-11 9:03
memberCarsten Leue29-Aug-11 9:03 
QuestionMS-SIPAE <-> SSPI: MakeSignature is 'GSS_GetMIC’? Pin
Member 265752125-Aug-11 23:08
memberMember 265752125-Aug-11 23:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 23 Aug 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid