Solved

keyboard::enter  code specific

Posted on 2007-11-28
5
301 Views
Last Modified: 2007-11-28
#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

void output ( string string1 );
void enter();

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

int main()
{
      EnumWindows(EnumWindowsProc,(LPARAM)"Star Wars Galaxies");

      Sleep ( 3000 );
      
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
            
            string string1;
            string1 = "i";
            output ( string1 );


      }

   return 0;
}


////////////////////////////////////////////
// send string -  working only in chat window and not
////////////////////////////////////////////




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);
      }
     
}




void enter()
{
      BYTE vk = LOBYTE(::MapVirtualKey(string1[i], 0));
 
         keybd_event(0D,vk,0,0);
         keybd_event(0D,vk,KEYEVENTF_KEYUP,0);
     
}






how do I send enter?

http://msdn2.microsoft.com/en-us/library/ms645540.aspx
http://msdn2.microsoft.com/en-us/library/ms646304.aspx


do have code for enter, if I can't use vkkeyscan then i ll write function just to send enter. or something.
0
Comment
Question by:Troudeloup
  • 2
  • 2
5 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 20369047
To send "enter", use VK_ENTER, e.g.

void enter()
{
      BYTE vk = LOBYTE(::MapVirtualKey(VK_ENTER, 0));
 
         keybd_event(VK_ENTER,vk,0,0);
         keybd_event(VK_ENTER,vk,KEYEVENTF_KEYUP,0);
     
}

The problem with "Enter" is that it will send it to the window that currently has the focus. If that is an edit box, that is a line break.
0
 

Author Comment

by:Troudeloup
ID: 20369083
this poped

switch_window_mouse_move.cpp:72: error: `VK_ENTER' was not declared in this scope


in here



#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

void output ( string string1 );
void enter();

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

int main()
{
      EnumWindows(EnumWindowsProc,(LPARAM)"Star Wars Galaxies");

      Sleep ( 5000 );
      
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
            
            string string1;
            string1 = "helloEEpeople";
            cout << "output!" << endl;
            enter ();
            output ( string1 );
            enter ();


      }

   return 0;
}


////////////////////////////////////////////
// send string -  working only in chat window and not
////////////////////////////////////////////




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);
      }
     
}


void enter()
{
      BYTE vk = LOBYTE(::MapVirtualKey(VK_ENTER, 0));
 
         keybd_event(VK_ENTER,vk,0,0);
         keybd_event(VK_ENTER,vk,KEYEVENTF_KEYUP,0);
     
}

0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 20369157
Arg, I'm stupid, it's VK_RETURN - try


#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

void output ( string string1 );
void enter();

vector<HWND> vw; // array for HWND

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
      char buf [1024];
      GetWindowText(hwnd,buf,1024);

      if(!strstr(buf,(char*)lParam)) return true;

       vw.push_back(hwnd);

      return true;
}

int main()
{
      EnumWindows(EnumWindowsProc,(LPARAM)"Star Wars Galaxies");

      Sleep ( 5000 );
     
      for (vector<HWND>::iterator i = vw.begin(); i != vw.end(); ++i)
      {
      // *i   = hwnd
           
            string string1;
            string1 = "helloEEpeople";
            cout << "output!" << endl;
            enter ();
            output ( string1 );
            enter ();


      }

   return 0;
}


////////////////////////////////////////////
// send string -  working only in chat window and not
////////////////////////////////////////////




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);
      }
     
}


void enter()
{
      BYTE vk = LOBYTE(::MapVirtualKey(VK_RETURN, 0));
 
         keybd_event(VK_RETURN,vk,0,0);
         keybd_event(VK_RETURN,vk,KEYEVENTF_KEYUP,0);
     
}
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 100 total points
ID: 20369198
>> Arg, I'm stupid, it's VK_RETURN - try
Tsk. Don't be so hard on yourself, even Savants have their moments :)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20369409
Troudeloup, whilst I am appreciative of the points, I did nothing to assist this in this question (I just poked fun at our new Savant) and jkr should have been awarded the full points.

Jkr, I will not object if you want to revert this question back to an open status so that Troudeloup can close it appropriately.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now