keybd_event()

B

bradfordh

I cannot seem to get this to work. How do I use this (or should I be
using SendInput() ) to send keystrokes to Iapplications/games? I know
I need to use a getfocus function. For instance, I could use
keybd_event() to send virtual keys to a game, but I cannot get it to
work. Here is a snipplet that I am trying to get it to only type a
letter on the screen. Can anybody see a problem? Thanks in advance.

#include <windows.h>
#include <iostream>
using namespace std;

void AltEnter(void);

int main()
{
Sleep(2000);

AltEnter();

Sleep(5000);
cout << "\nEnter 1 to end: ";
int number = 0;
while (number != 1) {
cin >> number;
}

return 0;
}

void AltEnter()
{
keybd_event(49,
0,
0,
0);
keybd_event(49,
0,
KEYEVENTF_KEYUP,
0);
return;
}
 
E

E. Robert Tisdale

I cannot seem to get this to work. How do I use this (or should I be
using SendInput() ) to send keystrokes to Iapplications/games?
I know I need to use a getfocus function. For instance, I could use
keybd_event() to send virtual keys to a game, but I cannot get it to
work. Here is a snipplet that I am trying to get it to only type a
letter on the screen. Can anybody see a problem?
cat main.cpp
#include <windows.h>
#include <iostream>

void AltEnter(void) {
keybd_event(49, 0, 0, 0);
keybd_event(49, 0, KEYEVENTF_KEYUP, 0);
return;
}


int main(int argc, char* argv[]) {
Sleep(2000);

AltEnter();

Sleep(5000);
std::cout << "\nEnter 1 to end: ";
int number = 0;
while (number != 1) {
std::cin >> number;
}

return 0;
}
g++ -Wall -ansi -pedantic -o main main.cpp
main.cpp:1:22: windows.h: No such file or directory
main.cpp: In function `void AltEnter()':
main.cpp:5: error: `keybd_event' undeclared \
(first use this function)
main.cpp:5: error: (Each undeclared identifier \
is reported only once for each function it appears in.)
main.cpp:6: error: `KEYEVENTF_KEYUP' undeclared \
(first use this function)
main.cpp: In function `int main(int, char**)':
main.cpp:12: error: `Sleep' undeclared (first use this function)

I can't even compile your program.
Are you sure that it wouldn't be better to ask this question
in one of the windows programming newsgroups?
 
K

Kurt Krueckeberg

I cannot seem to get this to work. How do I use this (or should I be
using SendInput() ) to send keystrokes to Iapplications/games? I know

Best to ask on microsoft.public.vc.language, and, yes, you should be using
SendInput()
 
L

lallous

I cannot seem to get this to work. How do I use this (or should I be
using SendInput() ) to send keystrokes to Iapplications/games? I know
I need to use a getfocus function. For instance, I could use
keybd_event() to send virtual keys to a game, but I cannot get it to
work. Here is a snipplet that I am trying to get it to only type a
letter on the screen. Can anybody see a problem? Thanks in advance.

#include <windows.h>
#include <iostream>
using namespace std;

void AltEnter(void);

int main()
{
Sleep(2000);

AltEnter();

Sleep(5000);
cout << "\nEnter 1 to end: ";
int number = 0;
while (number != 1) {
cin >> number;
}

return 0;
}

void AltEnter()
{
keybd_event(49,
0,
0,
0);
keybd_event(49,
0,
KEYEVENTF_KEYUP,
0);
return;
}

Hope this is of help:
http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top