Solved

sendinput    Windows NT/2000/XP: This function has been superseded. Use SendInput instead.

Posted on 2007-11-26
22
479 Views
Last Modified: 2010-04-01
SendInput

Windows NT/2000/XP: This function has been superseded. Use SendInput instead.


I was going to use


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
);



but they are superseded by sendinput



however, this page
http://msdn2.microsoft.com/en-us/library/ms646310.aspx


doesn't really explain how to use it.



how do I use sendinput to send keyboard and mouse events?




0
Comment
Question by:Troudeloup
  • 12
  • 10
22 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20352844
'Superseded' in that context does not mean that you cannot use it anymore. In fact it is still supported and easier to use than 'SendInput()'. Take a look at http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp ("SendKeys in C++") which still use that API to simluate VB's SendKeys.
0
 

Author Comment

by:Troudeloup
ID: 20352859
aww

i get it.

for the old ways, can you point me to their page with all the key codes?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20352886
Sure, that is located at http://www.codeproject.com/system/keyboard.asp ("Keyboard Events Simulation using keybd_event() function")
0
 

Author Comment

by:Troudeloup
ID: 20352893
how about mouse?
0
 

Author Comment

by:Troudeloup
ID: 20352905
make  = press
break  = release?


and where are keys for lower cases chars?
0
 

Author Comment

by:Troudeloup
ID: 20352928
VOID mouse_event(      
    DWORD dwFlags,                  // key actions, such as MOUSEEVENTF_LEFTDOWN
    DWORD dx,                       // screen x
    DWORD dy,                       // screen y
    DWORD dwData,                   // what's this?
    ULONG_PTR dwExtraInfo           // what's this?
);


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


0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20352936
For the lower-case keys, you can just use the virtual keycode (1st parameter), the scan code is the same (it is the same key anyway), e.g.

keybd_event('a',0x1e,0,0);

And 'Make' and 'Break' coresspond to 'press' and 'release'.

0
 

Author Comment

by:Troudeloup
ID: 20352964
keybd_event('a',0x1e,0,0);


a   //   if I put "A" here, does it mean it would be upper case?
0x1e   //  press
0       //   what does this mean?
0      //   what does this mean?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20352972
>>    DWORD dwData,                   // what's this?
>>    ULONG_PTR dwExtraInfo           // what's this?

These are only necessary for MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. You ca nset them both to '0'.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20352993
>>a   //   if I put "A" here, does it mean it would be upper case?

Yes, indeed. The virtual keycodes for letters correcpond directly to their ASCII values.
0
 

Author Comment

by:Troudeloup
ID: 20353054
>>    DWORD dwData,                   // what's this?
>>    ULONG_PTR dwExtraInfo           // what's this?

These are only necessary for MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. You ca nset them both to '0'.




does this mean I can click mouse and turn mouse wheel at the same time?    (wow)




how do I turn mouse wheel if I need to turn it?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20353095
Well, you can use

mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_WHEEL, 100, 100, 2400, NULL);

See also the docs at http://msdn2.microsoft.com/en-us/library/ms646260.aspx they have it all.
0
 

Author Comment

by:Troudeloup
ID: 20353136
how do I send a string to keyboard?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20353199
Well, like

keybd_event('D',0x20,0,0);
keybd_event('a',0x1e,0,0);
keybd_event('d',0x20,0,0);
keybd_event('d',0x20,0,0);
keybd_event('y',0x15,0,0);
0
 

Author Comment

by:Troudeloup
ID: 20353241
void output ( string string1 )
{
      int size = string1.size();

     int n = 0;
     while ( n < size )
    {
         switch string1[n]
 
         case "a"       keybd_event('a',0x1e,0,0);
        case  "A"      keybd_event(//placaholder );

   }

 }



how about something like this?




0
 

Author Comment

by:Troudeloup
ID: 20353284
for mouse events,


what if I just want to move the mouse wheel?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20353315
That you can do like

void output ( string string1 )
{
      int size = string1.size();

      for (int i = 0; i < size; ++i)
      {
         BYTE vk = LOBYTE(::MapVirtualKey(string1[i], 0));

         keybd_event(string1[i],vk,0,0);
         keybd_event(string1[i],vk,KEYEVENTF_KEYUP,0);
      }
0
 

Author Comment

by:Troudeloup
ID: 20353339
I don't get your code;

what is this?

   BYTE vk = LOBYTE(::MapVirtualKey(string1[i], 0));


it seems that you retrieved the bye code somehow ( extremely cool, btw)


but how does it work?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 20353365
That line looks up the scan code, so you don't have to manually provide a lookup table.
0
 

Author Comment

by:Troudeloup
ID: 20353369
how did you do that O_o ?
0
 

Author Comment

by:Troudeloup
ID: 20353384
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20353406
Yup, I will.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now