what am i doing wrong?

May 24, 2014 at 10:16pm
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)
May 24, 2014 at 10:21pm
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 May 24, 2014 at 10:22pm
May 24, 2014 at 10:42pm
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 =)
May 24, 2014 at 10:47pm
Do you have a #include <windows.h> at the top of your code?
May 24, 2014 at 10:51pm
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>
May 24, 2014 at 10:56pm
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.
May 24, 2014 at 11:01pm
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
May 24, 2014 at 11:02pm
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;
}
May 24, 2014 at 11:06pm
@Longdoublemain

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