Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

keybd_event problem

I'm sure I'm doing everything right, I've included windows.h and whenever I try to use the code I get the following error:

error LNK2028: unresolved token (0A000013) "extern "C" void __stdcall keybd_event(unsigned char,unsigned char,unsigned long,unsigned long)" (?keybd_event@@$$J216YGXEEKK@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

error LNK2019: unresolved external symbol "extern "C" void __stdcall keybd_event(unsigned char,unsigned char,unsigned long,unsigned long)" (?keybd_event@@$$J216YGXEEKK@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

What can be the problem?
[794 byte] By [can16358p] at [2007-11-11 8:32:42]
# 1 Re: keybd_event problem
Hi,

this is a linker error, which suggests, that you have not included the library/DLL in your project.
MSDN:
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.

Try adding user32.lib and re-link...

Cheers,

D
drkybelk at 2007-11-11 21:01:12 >
# 2 Re: keybd_event problem
what is method signature ? write a simple program by using method signature?
harish456 at 2007-11-11 21:02:12 >
# 3 Re: keybd_event problem
Hi,
there's some stuff on the Web. Tenor is: you shouldn't use keyb_event any more but rather use SendInput(...). You find the signature etc on the MSDN (msdn.microsoft.com). and example can be found here
http://www.codeguru.com/forum/showthread.php?t=81918

Enjoy.

D
drkybelk at 2007-11-11 21:03:16 >
# 4 Re: keybd_event problem
hi ,
i am new user and i have a question on methods. if u r willing please reply.
what is method signature ? write a simple program c=a+b by using method signature?
harish456 at 2007-11-11 21:04:17 >
# 5 Re: keybd_event problem
Hi,
I think there is a misunderstanding. There is no method called "signature(...)" that I know of (of course you can write one yourself if you like, but there's none specified in standard C++). The term signature is a meta-term that is used when you want to refer to what the inputs and outputs of a method/function are.
Example:
void f(int i)
{
}
the "signature of function f is that it takes an int parameter and returns void.
When I referred to the signature of SendInput(...) in my previous mail, I meant which parameters you have to supply and which return-values you get.
Hope that helps?

D
drkybelk at 2007-11-11 21:05:16 >
# 6 Re: keybd_event problem
Now there are no errors but;
what is the problem with making my console app. fullscreen?

keybd_event(VK_MENU,0,0,0);
keybd_event(VK_RETURN,0,0,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0);

there are no errors on compile but nothing happens when application launches?

also I want to use SendInput but I didn't understand much from its definition on MSDN library.
can16358p at 2007-11-11 21:06:22 >
# 7 Re: keybd_event problem
Hi,

what are you trying to do? The code fragment you posted generates some key-events, that is the operating system thinks you typed some keys, but what do you expect to happen?
I guess you want to send key strokes to the windows start button? The problem you have is (a) the keybord events are dispatched by the currently active top window (which might be your console box, which doesn't know what to do with your keystrokes?) and if your keystrokes really reach the desktop the order in which you send them won't show any visible effect. try

keybd_event(VK_MENU,0,0,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,0,0,0);
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0);

which would display your start-menu and close it again (you might just see a short flicker, depending how fast your computer is...)

Cheers,

D
drkybelk at 2007-11-11 21:07:20 >
# 8 Re: keybd_event problem
No, I'm trying to press alt+enter to go fullscreen.
I looked at the MSDN library and it did what it said there. (I looked at Alt and Enter's key values and the parameter list of the function and there was the above code I wrote), but after a research, I realized that second parameter is "not used" as it said in MSN library. There should be a virtual key code there and I found it, now it works.

The problem was of MSDN library which pointed that second parameter wrong.

MSDN says:

Parameters

bVk
[in] Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see Virtual-Key Codes.
bScan
This parameter is not used.
dwFlags
[in] Specifies various aspects of function operation. This parameter can be one or more of the following values.
KEYEVENTF_EXTENDEDKEY
If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP
If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo
[in] Specifies an additional value associated with the key stroke.

But actually that parameter IS used, anyway, it works now.
can16358p at 2007-11-11 21:08:18 >