Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,923 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,940 people online right now. Registration is fast and FREE... Join Now!




[C++]Sending Keystrokes Error

 
Reply to this topicStart new topic

[C++]Sending Keystrokes Error

HornyAZNBoy
12 Jan, 2008 - 12:56 PM
Post #1

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 6

I've tried this code but it dosen't work and says that 'Error line (39)... cannot have 4 arugements'. by the way I sue Visual C++.

CODE
keybd_event(VkKeyScan('H'), 0, 0, 0);

And this one don't work either.
CODE
keybd_event(VK_MENU, 0x38, 0, 0);

And this one too.
CODE
mouse_event(MOUSEEVENT_LEFTDOWN, X, Y, 0, 0)


Can some one tell me my problem. I think I'm using the wrong header, but I'm not sure.

CODE
#include <windows.h>

This is the only one I need right?
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: [C++]Sending Keystrokes Error
15 Jan, 2008 - 01:10 AM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
keybd_event() and mouse_event() need windows.h to be included.
Both functions take 4 arguments, you should not be getting that error.

Check for missing semicolons in your code. VC++ fails to pinpoint the exact location of the error on many occasions where semicolons are missing.

I'd advise you to use SendInput() instead as it supercedes keybd_event() and mouse_event().
User is offlineProfile CardPM
+Quote Post

HornyAZNBoy
RE: [C++]Sending Keystrokes Error
15 Jan, 2008 - 01:10 PM
Post #3

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 6

QUOTE(born2c0de @ 15 Jan, 2008 - 02:10 AM) *

keybd_event() and mouse_event() need windows.h to be included.
Both functions take 4 arguments, you should not be getting that error.

Check for missing semicolons in your code. VC++ fails to pinpoint the exact location of the error on many occasions where semicolons are missing.

I'd advise you to use SendInput() instead as it supercedes keybd_event() and mouse_event().


Would you give me an example of how to use the SendInput(). I'm a visual learner. the example microsoft gives me is not very clear.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: [C++]Sending Keystrokes Error
16 Jan, 2008 - 01:28 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Here's an excellent example of SendInput()
User is offlineProfile CardPM
+Quote Post

HornyAZNBoy
RE: [C++]Sending Keystrokes Error
19 Jan, 2008 - 10:36 AM
Post #5

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 6

QUOTE(born2c0de @ 16 Jan, 2008 - 02:28 AM) *

Here's an excellent example of SendInput()


Those are excelent examples but I cannot use them for keyboard events. Here is what I did to try to get it working for keyboard inputs.

CODE

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

  INPUT    AInput;
  memset(&aInput, 0, sizeof(INPUT));

  // key down
  Input.type = INPUT_KEYBD;
  //What do I do here?  
  //Input.ki.dwFlags  = ???;
  ::SendInput(1,&AInput,sizeof(INPUT));

  // key up
  Input.type = INPUT_KEYBD;
  //I have no idea what to do here too  
  //Input.ki.dwFlags  = ???;
  SendInput(1,&AInput,sizeof(INPUT));


This post has been edited by HornyAZNBoy: 19 Jan, 2008 - 10:41 AM
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: [C++]Sending Keystrokes Error
20 Jan, 2008 - 07:31 AM
Post #6

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
You can use either of these values to specify the dwFlags parameter.
  • KEYEVENTF_EXTENDEDKEY
    If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).
  • KEYEVENTF_KEYUP
    If specified, the key is being released. If not specified, the key is being pressed.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 02:52PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month