"Extern" Sendkey/ keybd_Event

BlitzMax Forums/BlitzMax Beginners Area/"Extern" Sendkey/ keybd_Event

Hi All,

Well, since I'm new to doing this, i was wondering if you all-knowing users out there could help:

I need to be able to use these functions in BlitzMax- SendKey is most preferable however.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputFunctions/keybd_event.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputFunctions/SendInput.asp

I was wondering if any of you could get these working in BlitzMax? I don't know enough about them to do it myself, but I am willing to learn so if someone does it could you explain a bit about what was done?

Call this a hole in my knowledge! :D

Cheers for your help.


Strict

Graphics 800,600

Repeat
	Cls()
	
	If KeyDown(KEY_A)
		EmitEvent CreateEvent(EVENT_KEYDOWN,Null,KEY_G)
	Else
		EmitEvent CreateEvent(EVENT_KEYUP,Null,KEY_G)
	EndIf
	
	If KeyDown(KEY_G)
		DrawText "G is pressed",0,0
	Else
		DrawText "G is released",0,0
	EndIf
	
	If KeyDown(KEY_ESCAPE) End
	Flip()
Forever


here's a simple way to do it, plus it's cross-platform.

Thanks for the idea, but this doesn't quite do what I need (I need to send a print_screen so that windows itself thinks I pressed it, and actually does the print screen)

However, thanks for this code. I wasn't aware of this functionality in max. You just made a crapload of my code obsolete!! ;)

Extern "win32"
	Function keybd_event(bVk:Byte,bScan:Byte,dwFlags,dwExtraInfo Ptr)
End Extern


i tried SendInput but because of the way BlitzMax handles Types makes it very hard to use SendInput.

This will do, Thanks very much.

Damn, looked easy too :) Time to test it!

I would like to say Thanks to Khomy Prime. This code got around a huge problem we were having- Thanks!

I have some code in the archives that uses SendInput to simulate mouse clicks. Would be a good basis for someone wanting to add keyboard input.

Yeah, the ability to simulate mouse input is great. The problem I was having was that I was using blitzmax but rendering in another window, without a max window being active, so no Max input (keyboard or mouse) would work. The above worked perfectly. I didnt know about the mouse stuff originally and thought I would be stuck. I never knew how easy it was :)

oops...lol just noticed this...you're welcome Cygnus, anytime.