Error with GetAsyncKeyState.
Mar 10, 2013 at 6:01pm UTC
Hi people. I am new one on programming. Today i wanted to make a simple game or something like that, but I get an error with GetAsyncKeyState. I searched that everythere but found nothing helpfull... I would be very thankfull if you help me with that :).
SOLVED
I added user32.lib to project > properties > linker > imput > aditional dependencies.
here's my unfinished program:
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#include <iostream>
#include <ctime>
#include "windows.h"
using namespace std;
char map[10][30] = {
"#############################" ,
"#@ ++ #" ,
"# #" ,
"# + #" ,
"# #" ,
"# + #" ,
"# + #" ,
"# #" ,
"# O#" ,
"#############################" ,
};
int x = 1;
int y = 1;
int iPinigai = 0;
double frameCount = 0;
double startTime = timeGetTime();
double lastTime = 0;
void timerUpdate(void )
{
double currentTime = timeGetTime() - lastTime;
if (currentTime < 1000)
return ;
frameCount++;
lastTime = timeGetTime();
}
void cursorVisibility(bool visibility)
{
HANDLE output_handle;
CONSOLE_CURSOR_INFO cciInfo;
cciInfo.dwSize = 1;
cciInfo.bVisible = visibility;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(output_handle, &cciInfo);
}
int main() {
cursorVisibility(false );
bool game_running = true ;
while (game_running = true ) {
system ("CLS" );
for (int display = 0; display < 10; display++) {
cout << map[display] << endl;
}
cout << "\nYour money: " << iPinigai << endl;
system ("pause > 0" );
if (GetAsyncKeyState(VK_DOWN)) {
int y2 = y + 1;
if (map[y2][x] == ' ' ) {
map[y][x] = ' ' ;
y++;
map[y][x] = '@' ;
}
if (map[y2][x] == '+' ) {
iPinigai = iPinigai + 1;
map[y][x] = ' ' ;
y++;
map[y][x] = '@' ;
}
}
if (GetAsyncKeyState(VK_UP)) {
int y2 = y - 1;
if (map[y2][x] == ' ' ) {
map[y][x] = ' ' ;
y--;
map[y][x] = '@' ;
}
if (map[y2][x] == '+' ) {
iPinigai = iPinigai + 1;
map[y][x] = ' ' ;
y--;
map[y][x] = '@' ;
}
}
if (GetAsyncKeyState(VK_RIGHT)) {
int x2 = x + 1;
if (map[y][x2] == ' ' ) {
map[y][x] = ' ' ;
x++;
map[y][x] = '@' ;
}
if (map[y][x2] == '+' ) {
iPinigai = iPinigai + 1;
map[y][x] = ' ' ;
x++;
map[y][x] = '@' ;
}
}
if (GetAsyncKeyState(VK_LEFT)) {
int x2 = x - 1;
if (map[y][x2] == ' ' ) {
map[y][x] = ' ' ;
x--;
map[y][x] = '@' ;
}
if (map[y][x2] == '+' ) {
iPinigai = iPinigai + 1;
map[y][x] = ' ' ;
x--;
map[y][x] = '@' ;
}
}
if (GetAsyncKeyState(VK_ESCAPE)) {
game_running = false ;
}
}
cout << "\nGAME OVER!" << endl;
return 0;
}
aaaaand theres the errors whitch i get :(
1>Zaidimas.obj : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function _main
1>d:\dokumentai\visual studio 2010\Projects\Zaidimas2\Debug\Zaidimas2.exe : fatal error LNK1120: 1 unresolved externals
Last edited on Mar 10, 2013 at 6:56pm UTC
Topic archived. No new replies allowed.