Solved

upper case kb_event!

Posted on 2007-11-28
5
921 Views
Last Modified: 2008-02-01
#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)"notepad");

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


      }

   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
Comment
Question by:Troudeloup
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20369481
What is your question here?
0
 

Author Comment

by:Troudeloup
ID: 20369521
the output is all in lower case


which is not string1,

hw do I correct it?
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 20372097
>>>> the output is all in lower case
You'll get upper case if you set the VK_SHIFT as well.

>>>> which is not string1

but?

Regards, Alex
0
 

Author Comment

by:Troudeloup
ID: 20386524
how do I fix this?



string string1 = "VK_RETURN";

BYTE vk = LOBYTE(::MapVirtualKey( string1, 0));
keybd_event( string1,vk,0,0);
keybd_event( string1,vk,KEYEVENTF_KEYUP,0);
     
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20386819
>>>> how do I fix this?

You could try

void output ( string string1 )
{
      int size = string1.size();

      for (int i = 0; i < size; ++i)
      {
         char c = string1[i];   // the char
         unsigned short scan = VkKeyScan(c);  // the scan code for c
         unsigned char  vk  = (scan & 0xff);   // == LOBYTE(scan)
         unsigned char  sac = scan >> 8;      // == HIBYTE(scan)
         unsigned char  mvk = (unsigned char)MapVirtualKey(c, 0);
         if (sac & 1)   // shift must be pressed additionally
               keybd_event(VK_SHIFT, (unsigned char)MapVirtualKey(VK_SHIFT,0), 0, 0);

         keybd_event(vk, mvk, 0, 0);
         keybd_event(vk, mvk, KEYEVENTF_KEYUP, 0);

         if (sac & 1)   // shift must be released
               keybd_event(VK_SHIFT, (unsigned char)MapVirtualKey(VK_SHIFT,0), KEYEVENTF_KEYUP, 0);

      }
     
}

Note:

     (sac & 2)   would indicate the CTRL key was pressed additionally
     (sac & 4)   would indicate the ALT key was pressed additionally
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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