Solved

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

Posted on 2007-11-28
4
760 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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 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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 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