what am i doing wrong?

so I am trying to implement the following code

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
  void PressKey(WORD key, int x)
{
	int y = 0;
	while(y <= x)
	{
		SetForegroundWindow(eveWindow);
		Sleep(200 + rand() % 250);

		INPUT *keyClick;
		keyClick = new INPUT;
		keyClick->ki.wVk = key;
		keyClick->type = INPUT_KEYBOARD;
		keyClick->ki.dwFlags = 0;
		keyClick->ki.time = 0;
		keyClick->ki.wScan = 0;
		keyClick->ki.dwExtraInfo = 0;


		SendInput(1,keyClick,sizeof(INPUT));
	
		Sleep(100);

		keyClick->ki.dwFlags = KEYEVENTF_KEYUP;

		SendInput(1,keyClick,sizeof(INPUT));
		y++;
	}
	return 0;
}


but i get these errors

main.cpp: In function `void PressKey(WORD, int)':
main.cpp:79: error: `INPUT' was not declared in this scope
main.cpp:79: error: `keyClick' was not declared in this scope
main.cpp:80: error: `INPUT' is not a type
main.cpp:82: error: `INPUT_KEYBOARD' was not declared in this scope
main.cpp:89: error: `SendInput' was not declared in this scope
main.cpp:98: error: return-statement with a value, in function returning 'void'
make.exe[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make.exe[2]: Leaving directory `/c/Users/John K. Hackett/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/John K. Hackett/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)
Is PressKey supposed to be a member function of an INPUT class?


main.cpp:98: error: return-statement with a value, in function returning 'void'

You have a return statement in the function, but you've defined it as a void function. Void functions don't return anything.
Last edited on
Is PressKey supposed to be a member function of an INPUT class?
I believe so yes, i found the coding elsewhere, so i am not too sure how it does what it does. I thought it was in one of the #includes


You have a return statement in the function, but you've defined it as a void function. Void functions don't return anything.

yea i do... I'll correct that =)
Do you have a #include <windows.h> at the top of your code?
Do you have a #include <windows.h> at the top of your code?

yes

#include <windows.h>
#include <stdio.h>
#include <iostream> // for cout and cin
#include <time.h> // For seeding random
using namespace std;
#include <cstdlib> // for the system() function
#include <fstream>
#include <string>
#include <sstream>
closed account (j3Rz8vqX)

main.cpp:79: error: `INPUT' was not declared in this scope
main.cpp:79: error: `keyClick' was not declared in this scope
main.cpp:80: error: `INPUT' is not a type
main.cpp:82: error: `INPUT_KEYBOARD' was not declared in this scope

Input needs to be declared before this class or function.
Found a couple of posts with a similar issue even though they included windows.h where INPUT is supposed to be defined - there are some solutions offered that might help.

http://stackoverflow.com/questions/22432889/input-input-keyboard-ip-were-not-declared-in-this-scope

http://stackoverflow.com/questions/11596219/input-was-not-declared-in-this-scope?rq=1
The INPUT and SendInput stuff should be in winuser.h, which should be #include d by windows.h.
Does this program compile for you?
1
2
3
4
5
6
7
#include <windows.h>

int main()
{
    INPUT foo;
    (void)SendInput;
}
@Longdoublemain

I get the same error with that.
Okay, how about if you change the windows.h part to winuser.h?
Don't know why but adding in #include <winable.h> makes it work
I don't think winable.h is part of the Windows SDK anymore.
You should be able to use winuser.h. instead.
at least the INPUT stuff, my main program still isn't running
What errors are you getting now?
Looks pretty strange. i'd like to see the whole code.
Topic archived. No new replies allowed.