Jump to content

Executing windows button presses

- - - - -

  • Please log in to reply
7 replies to this topic

#1
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
I am trying to figure out how to have my code execute 'button press' functions. Such as, when I press button 'x' It will execute a loop too continually execute certain windows buttons. Something like this:


bool cancel = true;


if (BUTTON X IS PUSHED)

{


do{


// execute button

// execute button

// execute button

// etc.

if(BUTTON X IS PUSHED)

{

cancel = false;

}


}while(cancel)

}


Basically it is to be like a macroing program. I am wondering what would be the statements for the program to execute these buttons and, what would be the statements to look for when I push a button to cancel the looping?

#2
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

Can you clarify a bit?

What language you're using VC++ MFC? Do you want to execute button press on the same windows or some other Windows button from your application?

Munir

#3
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
No, I was going to leave this in a console application so it can run in the background and can execute on physical key presses.

#4
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Ah! did that mean you want to capture keyevents?

Munir

#5
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
That sounds about right, I want it to be able too execute keypresses when a certain key is pressed.

Ex. Button 'r' is pushed.
Program outputs '1, 2, 3'

#6
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

This should help you.

Writing Keyloggers - DocDroppers

Before you go for that: read following!

You can use GetKeyState or GetAsyncKeyState, but that won't give you keydown/keyup events. It will only tell you what keys are currently down.

So if you really need to get the keydown/keyup events, you could install a hook. A Console window has a window handle that is owned by code in Windows and a message pump, also owned by code in Windows.

You can get the window handle of of the console window by using GetConsoleWindowThen install a WH_CALLWNDPROC hook using SetWindowsHookEx to listen in on messages send to the console window.

You might try a WH_MSGFILTER hook instead. I don't know if this works for console windows, but it would generate less messages to be ignored if it does work.

I hope this helps!

Munir

#7
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
Woah, a lot more too it than I thought! Thank you! I will take a look at this and post back later if I need more help.

#8
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

I'd suggest first to read through the paragraph I provided: First, you should determine how could you capture events, and then specifically key events.

The links I sent you contains the source code for hooking keyboard events, and then translating then in message processing loop: this should help you understanding the mechanism.

If you still got the questions. Let us know!

Munir




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users