473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

keybd_event()

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;
}

Jul 22 '05 #1
3 11345

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()
Jul 22 '05 #2
br*******@gmail.com wrote:
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?
Jul 22 '05 #3
<br*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

--
Elias
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: newsgroups.bellsouth.net | last post by:
I was checking out SAPI, ms's speech recognition api, and thought it would be cool to write a quick app for bf1942 that would recognise voice commands and pass them to the game's commun. So if you...
0
by: chris | last post by:
I'm trying to send keystrokes to an external fullscreen directx game. I've tried sendkeys, sendinput, keybd_event, and sendmessage without luck. Public Sub Roger() PressKeyVK keyf1 PressKeyVK...
1
by: chella | last post by:
ok. I have finally got to the point where Im about to give up on that... I thought maybe you guys can help I have an ascii code (suppose 65 for the letter 'A') and have to use the function...
5
by: Wayne Gibson | last post by:
Hi, Was wondering if somebody could help.. I'm trying to use Sendkeys on a Windows forms. I have entered the following command to simulate a CTRL+ALT+1.. ...
3
by: msnews.microsoft.com | last post by:
Hi i am using User32.dll in Visual stdio 2005. public static extern long SetActiveWindow(long hwnd); public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
1
by: roshan | last post by:
All, Hello. I am a Software Developer currently creating an emulation program for our company's System Administrator. He will be able to call the program and emulate any keyboard combination,...
1
by: Figmo | last post by:
Wow.....this is darned odd.... I have an app that integrates with other applications. It registers a global hotkey with Windows. When the hotkey executes it sends a CTRL-C to the active...
0
by: wimpos | last post by:
Hi devs I'm develloping for Windows Mobile 6 (HTC TYTN II) in C# .NET 2.0 Information: I defined a windows keyboard hook, so my application listens to all key hits. When one specific key is...
0
by: ngeluis | last post by:
Hello every one.. Im having problems to send a command to Windows - Run... I want to send a command to Windows - Run to the people only have to press the Enter Key... The text that i want to...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.