Solved

keyboard and mouse events - specific code

Posted on 2007-11-25
6
299 Views
Last Modified: 2010-04-01
http://www.experts-exchange.com/Programming/Languages/CPP/Q_22981302.html#a20346828

I tried to read these

http://msdn2.microsoft.com/en-us/library/ms646260.aspx
http://msdn2.microsoft.com/en-us/library/ms646304.aspx


VOID keybd_event(      
    BYTE bVk,
    BYTE bScan,
    DWORD dwFlags,
    PTR dwExtraInfo
);




VOID mouse_event(      
    DWORD dwFlags,
    DWORD dx,
    DWORD dy,
    DWORD dwData,
    ULONG_PTR dwExtraInfo
);


0
Comment
Question by:Troudeloup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20346974
E.g.

// Simulating a Alt+Tab keystroke
keybd_event(VK_MENU,0xb8,0 , 0); //Alt Press
keybd_event(VK_TAB,0x8f,0 , 0); // Tab Press
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release

See the artivle at http://www.codeproject.com/system/keyboard.asp ("Keyboard Events Simulation using keybd_event() function") for more in-depth information.

For the mouse, that would be

 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()); // Left Key Down
 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()); // Left Key UP
 
 mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, GetMessageExtraInfo()); // Right Key Down
 mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, GetMessageExtraInfo()); // Right Key Up

You'd usually specify mouse coordinates as teh 2nd and 3rd parameter.
0
 

Author Comment

by:Troudeloup
ID: 20346988
is it possible to tell mouse to move across the screen, not an instance move?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20347006
Yes, for that you'd use 'SetCursorPos()' (http://msdn2.microsoft.com/en-us/library/ms648394.aspx), e.g.

for (int i = 0; i < 100; ++i) {

  SetCursorPos(i,200);
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Troudeloup
ID: 20347014
wow a loop

oh boy this will be fun

I have to write loops to move mouse in a straight line!
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20347026
Well, the above line would already do that vertically. to move horizontally, use

for (int i = 0; i < 100; ++i) {

  SetCursorPos(200,i);
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question