Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-28
4
Medium Priority
?
765 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

879 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