Solved

keyboard::enter  code specific

Posted on 2007-11-28
5
321 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

713 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