[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

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);

}
0
thatsgreat2345
Asked:
thatsgreat2345
  • 7
  • 4
  • 2
  • +1
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
Raj_KauCommented:
thanks thatsgreat2345


Raj
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now