Creating simple keypresser

Hello guys,

I would like to ask if anyone maybe know how to create simple key presser program in Visual Studio, using C# or C++ language.
I would need that program for some game (like a macro), but sadly for my game I alredy tried tons of keypressers and they are either detected by hackshield, or they don't work as I would like them to.

So basicly what I need:
send key "8", wait 3 sec, send key "2", wait 2 sec, send key 1, wait 3min and start from beggining. It seems kinda simple, but I still don't know how to make it.
For starters I would like to make it just like that, but more advanced it would be, if it coul work in background for specific window only, so I can do other stuffs on my PC while keypresser is working.

If anyone have any idea how to make this, please let me know :)
For Windows/C++ look at SendInput: https://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx

C# probably has the way of doing so in its vast library somewhere.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

//
// keystroke.c - Pauses, then simulates a key press
// and release of the "A" key.
//
// Written by Ted Burke - last updated 17-4-2012
//
// To compile with MinGW:
//
//      gcc -o keystroke.exe keystroke.c
//
// To run the program:
//
//      keystroke.exe
//
// ...then switch to e.g. a Notepad window and wait
// 5 seconds for the A key to be magically pressed.
//
 
// Because the SendInput function is only supported in
// Windows 2000 and later, WINVER needs to be set as
// follows so that SendInput gets defined when windows.h
// is included below.
#define WINVER 0x0500
#include <windows.h>
 
int main()
{
    // This structure will be used to create the keyboard
    // input event.
    INPUT ip;
 
    // Pause for 5 seconds.
    Sleep(5000);
 
    // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;
 
    // Press the "A" key
    ip.ki.wVk = 0x38; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));
 
    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));
 	Sleep(5000);
  // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;
 
    // Press the "A" key
    ip.ki.wVk = 0x32; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));
 
    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));
    
    Sleep(2000);
    	
  // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;
 
    // Press the "A" key
    ip.ki.wVk = 0x31; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));
 
    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));
    // Exit normally
    return 0;
}


I tried this code and it works great when I run and bring notepad to front. It will write 821 with delays that I need.
However, when I run this script and bring my game to front, it won't give any input there.
It seems like it works for everthing except games ...

Any idea how to solve this? I'm playing game called KalOnline
YOur game is probably listens to keyboard directly instead of relying on messages.

In this case a virtual keyboard + sending messages to virtual keyboard might help, but I am not sure about that. You may try.
Hmmm I would try it, if you could please be a bit more specific, how to do that :)
I'm new in this and still need some help figuring things out
Check if your game works when using standard Windows On-Screen keyboard first.
Topic archived. No new replies allowed.