Solved

c++ code - keyboard simulation - not just string into edit area

Posted on 2007-11-28
4
758 Views
Last Modified: 2008-02-01
in script language auto it 3

there is this command

send ( "string haha!")

that would automaitcally send exact string to the keyboard.

not only that, if I try

send ( "i" ) in a game,  it would also then prompt the game to do whatever that is done by pressing "i"



however, when I do this



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

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




it would only send "i" to the chat window, if the cursor were focused there, but not if i want the game to press "i"


how do I do what I can do with auto it 3 in c++?
0
Comment
Question by:Troudeloup
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20369086
As I wrote in your other Q, that is a matter of which window currently has the focus. You need to use 'SetActiveWindow()' from your code to set the focus to the window that should receive the keypress.
0
 

Author Comment

by:Troudeloup
ID: 20369095
i manually focus on the tartget window :(
0
 

Author Comment

by:Troudeloup
ID: 20369136
actually it works now.
0
 
LVL 86

Expert Comment

by:jkr
ID: 20369141
Then, you need to do that using code. AutoIt uses the same means.
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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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.
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.

867 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

16 Experts available now in Live!

Get 1:1 Help Now