Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-28
4
Medium Priority
?
764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

722 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