Question:
In this C++ program, how would I output things like a period, comma, etc?
Alfred
2010-05-22 10:44:10 UTC
I'm making a program that will ask a user for an application window to select and a text file to read off of. The program will then look at the text file and write its contents onto whatever application window the user chose. I've gotten it working fine except for one thing: it won't write things like periods. I got it to hit enter when it encounters a new line, but for some reason the hex for period doesn't do anything.

#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;



bool isLower (char ch);
bool isCaps (char ch);
char convert (char ch);
void otherChars (char ch);
/* This is a function to simplify usage of sending keys */
void GenerateKey(int vk, BOOL bExtended);





int main() {

ifstream ins;
string fileName;
string Window;
char i;


cout << "Enter the name of the window: ";
getline(cin, Window);
cout << endl;


cout << "Enter filename: ";
cin >> fileName;



/* HWND = "Window Handle" */
HWND UserWindow = FindWindowA(0, Window.c_str());

SetForegroundWindow(UserWindow);

ins.open( fileName.c_str() );

while (!ins.eof())
{
ins.get(i);

if (isCaps(i))
{
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey(i, FALSE);
GenerateKey(VK_CAPITAL, TRUE);
}
else if (isLower(i))
{
GenerateKey(convert(i), FALSE);
}
//If it's a new line, press enter
else if (i == '\n')
{
GenerateKey(0x0D, FALSE);

}
else if (i == ' ')
{
GenerateKey(' ', FALSE);
}
else
{
otherChars(i);
}

}


return 0;
}

void GenerateKey(int vk, BOOL bExtended) {

KEYBDINPUT kb = {0};
INPUT Input = {0};

//Generate a "key down"
if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }

kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));

// Generate a "key up"
ZeroMemory(&kb, sizeof(KEYBDINPUT));
ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));

return;
}

bool isCaps(char ch)
{
if ('A' <= ch && ch <='Z')
return true;
else
return false;
}

bool isLower(char ch)
{
if ('a' <= ch && ch <='z')
return true;
else
return false;
}
char convert (char ch)
{
ch = ch - 32;
return ch;
}
void otherChars (char ch)
{
if (ch == '.')
{
GenerateKey(ch, FALSE);
}
}
Three answers:
Onions
2010-05-22 11:10:41 UTC
tbshmkr, instead of having your head up your *** and giving a stupid answer in a desperate attempt to get another 10 points, why don't you actually read the content of the question?



With that said, you could do something like this in the otherChars function:



void otherChars (char ch)

{

if (ch == '.')

keybd_event(VkKeyScan('.'),0,0,0);

}
?
2016-11-06 05:45:29 UTC
do not ignore you could shop a replica as a C-string and the unique value. Iterate to the null and back one. print, iterate, print, iterate, print. print comma, iterate, print, etc. whilst the iterator is decrease than the call of the string, end. you would be checking the pointer itself, here - the memory handle. There are purposes that do it already - even regardless of the undeniable fact that it is going to likely be extra constructive in case you locate them your self. sturdy success!
tbshmkr
2010-05-22 10:54:30 UTC
cout <<"Output is: " << ". " << ", "" << "? " << endl;

=

Output is: . , ?

-

Without an example, cannot be more specific.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...