Solved

keyboard and mouse events - specific code

Posted on 2007-11-25
6
283 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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
 

Author Comment

by:Troudeloup
ID: 20352670
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 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