• C

C Sendinput

could someone reccomend a way to fix this or fix it for me, or reccomend a better compiler, im using microsoft visual C++ 6.0 and i think its pretty old so when i try to compile this i get a bunch of errors so if you could show me where to download something that can do it, or fix it if there are errors that would be great

#include <stdio.h>

void GenerateKey ( int vk , BOOL bExtended)
{
  KEYBDINPUT  kb={0};
  INPUT    Input={0};
  // generate down
  if ( bExtended )
    kb.dwFlags  = KEYEVENTF_EXTENDEDKEY;
  kb.wVk  = vk;  
  Input.type  = INPUT_KEYBOARD;

  Input.ki  = kb;
  ::SendInput(1,&Input,sizeof(Input));

  // generate up
  ::ZeroMemory(&kb,sizeof(KEYBDINPUT));
  ::ZeroMemory(&Input,sizeof(INPUT));
  kb.dwFlags  =  KEYEVENTF_KEYUP;
  if ( bExtended )
    kb.dwFlags  |= KEYEVENTF_EXTENDEDKEY;

  kb.wVk    =  vk;
  Input.type  =  INPUT_KEYBOARD;
  Input.ki  =  kb;
  ::SendInput(1,&Input,sizeof(Input));
}

while(1) {

GenerateKey(VK_F1, TRUE);

Sleep(1);

}
thatsgreat2345Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brettmjohnsonCommented:
This appears to be C++ code, so if you are compiling it as if it were ANSI C,
it will surely generate many compiler errors.   If this is the entire contents
of the source file, there are many undeclared types and unprototyped methods
and functions.  The presence of the Sleep() call (in its capitalized form) indicates
that this code is probably intended for Microsoft Windows, so compiling it on
another platform would also generate errors.
0
thatsgreat2345Author Commented:
yeah i got the script from here

http://www.codeguru.com/forum/showthread.php?t=377393

if anyone could point me to a site that shows how to use sendinput?
0
Raj_KauCommented:
i think its better if u tell what error exectly you get.

Raj
0
Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

thatsgreat2345Author Commented:
um i get 33 errors basicaly the entire thing
0
AlexFMCommented:
There is nothing in this code which cannot be compiled in VC++ 6.0. Since you didn't post list of errors, I try to guess. SendInput function is not supported in all operating systems. For such functions refer to this page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

0
AlexFMCommented:
BTW, add line:

#include <windows.h>
0
thatsgreat2345Author Commented:
i found a new script that sum1 said works but it gives me 1 error
 error C2447: missing function header (old-style formal list?)



#include <windows.h>

{
      KEYBDINPUT  kb={0};
  INPUT    Input={0};
 
  // down
  kb.wVk  = 'A';  
  Input.type  = INPUT_KEYBOARD;
  Input.ki  = kb;
  ::SendInput(1,&Input,sizeof(Input));


  // up
  ::ZeroMemory(&kb,sizeof(KEYBDINPUT));
  ::ZeroMemory(&Input,sizeof(INPUT));
  kb.dwFlags  =  KEYEVENTF_KEYUP;
  kb.wVk    =  'A';
  Input.type  =  INPUT_KEYBOARD;
  Input.ki  =  kb;
  ::SendInput(1,&Input,sizeof(Input));
}
0
Raj_KauCommented:
hey you miss function name

#include <windows.h>
void main()
{
     KEYBDINPUT  kb={0};
  INPUT    Input={0};
 
  // down
  kb.wVk  = 'A';  
  Input.type  = INPUT_KEYBOARD;
  Input.ki  = kb;
  ::SendInput(1,&Input,sizeof(Input));


  // up
  ::ZeroMemory(&kb,sizeof(KEYBDINPUT));
  ::ZeroMemory(&Input,sizeof(INPUT));
  kb.dwFlags  =  KEYEVENTF_KEYUP;
  kb.wVk    =  'A';
  Input.type  =  INPUT_KEYBOARD;
  Input.ki  =  kb;
  ::SendInput(1,&Input,sizeof(Input));
}

try this

Raj
0
Raj_KauCommented:
because the error you write come when you missing somethingh and here you miss function name
0
thatsgreat2345Author Commented:
UGHHH NOW ITS WORSE
#include <windows.h>
void main()
{
     KEYBDINPUT  kb={0};
  INPUT    Input={0};
 
  // down
  kb.wVk  = 'A';  
  Input.type  = INPUT_KEYBOARD;
  Input.ki  = kb;
  ::SendInput(1,&Input,sizeof(Input));


  // up
  ::ZeroMemory(&kb,sizeof(KEYBDINPUT));
  ::ZeroMemory(&Input,sizeof(INPUT));
  kb.dwFlags  =  KEYEVENTF_KEYUP;
  kb.wVk    =  'A';
  Input.type  =  INPUT_KEYBOARD;
  Input.ki  =  kb;
  ::SendInput(1,&Input,sizeof(Input));
}



J:\asdf.cpp(4) : error C2065: 'KEYBDINPUT' : undeclared identifier
J:\asdf.cpp(4) : error C2146: syntax error : missing ';' before identifier 'kb'
J:\asdf.cpp(4) : error C2065: 'kb' : undeclared identifier
J:\asdf.cpp(4) : error C2059: syntax error : '{'
J:\asdf.cpp(4) : error C2143: syntax error : missing ';' before '{'
J:\asdf.cpp(4) : error C2143: syntax error : missing ';' before '}'
J:\asdf.cpp(5) : error C2065: 'INPUT' : undeclared identifier
J:\asdf.cpp(5) : error C2146: syntax error : missing ';' before identifier 'Input'
J:\asdf.cpp(5) : error C2065: 'Input' : undeclared identifier
J:\asdf.cpp(5) : error C2059: syntax error : '{'
J:\asdf.cpp(5) : error C2143: syntax error : missing ';' before '{'
J:\asdf.cpp(5) : error C2143: syntax error : missing ';' before '}'
J:\asdf.cpp(8) : error C2228: left of '.wVk' must have class/struct/union type
J:\asdf.cpp(9) : error C2228: left of '.type' must have class/struct/union type
J:\asdf.cpp(9) : error C2065: 'INPUT_KEYBOARD' : undeclared identifier
J:\asdf.cpp(10) : error C2228: left of '.ki' must have class/struct/union type
J:\asdf.cpp(11) : error C2039: 'SendInput' : is not a member of '`global namespace''
J:\asdf.cpp(11) : error C2065: 'SendInput' : undeclared identifier
J:\asdf.cpp(13) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

asdf.obj - 19 error(s), 0 warning(s)
0
Raj_KauCommented:
means your first error not coming now
0
Raj_KauCommented:
and if you want then you can read this also

http://www.codeguru.com/forum/showthread.php?t=227330


Raj
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Raj_KauCommented:
thanks thatsgreat2345


Raj
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.