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

x
?
Solved

keyboard::enter  code specific

Posted on 2007-11-28
5
Medium Priority
?
346 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 1600 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 1600 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

877 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