Solved

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

Posted on 2007-11-28
4
757 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
Comment Utility
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
Comment Utility
i manually focus on the tartget window :(
0
 

Author Comment

by:Troudeloup
Comment Utility
actually it works now.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Then, you need to do that using code. AutoIt uses the same means.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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

11 Experts available now in Live!

Get 1:1 Help Now