Troudeloup
asked on
upper case kb_event!
#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,102 4);
if(!strstr(buf,(char*)lPar am)) return true;
vw.push_back(hwnd);
return true;
}
int main()
{
EnumWindows(EnumWindowsPro c,(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(str ing1[i], 0));
keybd_event(VkKeyScan(stri ng1[i]),vk ,0,0);
keybd_event(VkKeyScan(stri ng1[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,K EYEVENTF_K EYUP,0);
}
#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,102
if(!strstr(buf,(char*)lPar
vw.push_back(hwnd);
return true;
}
int main()
{
EnumWindows(EnumWindowsPro
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(str
keybd_event(VkKeyScan(stri
keybd_event(VkKeyScan(stri
}
}
void enter()
{
BYTE vk = LOBYTE(::MapVirtualKey(VK_
keybd_event(VK_RETURN,vk,0
keybd_event(VK_RETURN,vk,K
}
What is your question here?
ASKER
the output is all in lower case
which is not string1,
hw do I correct it?
which is not string1,
hw do I correct it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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);
string string1 = "VK_RETURN";
BYTE vk = LOBYTE(::MapVirtualKey( string1, 0));
keybd_event( string1,vk,0,0);
keybd_event( string1,vk,KEYEVENTF_KEYUP
>>>> 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_SHIF T,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_SHIF T,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
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_SHIF
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_SHIF
}
}
Note:
(sac & 2) would indicate the CTRL key was pressed additionally
(sac & 4) would indicate the ALT key was pressed additionally