OS KeyDown() emulation [WIN]

BlitzMax Forums/BlitzMax Programming/OS KeyDown() emulation [WIN]

mingw(Posted 2016) [#1]
Hello!
Requires that if a condition is met for the operating system were run event of the pressed key on the keyboard. Without physically pressing it.

???


Henri(Posted 2016) [#2]
Hi,

some more information is needed I think. If you want to just create an KeyDown event like for example for MaxGui then answer is simply PostEvent() of your choice. For what do you need it for ?

-Henri


mingw(Posted 2016) [#3]
I need to issue keys to the active window. And can be active for another application. Create a program-similar XPadder with new ideas. =)


Henri(Posted 2016) [#4]
You could try SendInput: https://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx


mingw(Posted 2016) [#5]
Thanks!

i'm find : http://www.blitzmax.com/Community/posts.php?topic=48863


Henri(Posted 2016) [#6]
For informational purposes here is an example of SendInput which is perhaps a bit more complicated for a beginner:
Strict

Const INPUT_MOUSE:Int = 0
Const INPUT_KEYBOARD:Int = 1
Const INPUT_HARDWARE:Int = 2

Const KEYEVENTF_KEYUP:Int = 2
Const KEYEVENTF_UNICODE:Int = 4

Extern "Win32"
	Function SendInput:Int(nInputs:Int, pInputs:Byte Ptr, cbSize:Int)
EndExtern


'EXAMPLE
For Local i:Int = 49 Until 91
	SendChar(i)
Next

End


Function SendChar(char:Int)
	Local in:TInput = New TInput
	in.key = char
	
	'Send key press
	SendInput(1, in, SizeOf(in) )
	
	'Signal key up
	in.dwFlags = KEYEVENTF_KEYUP
	SendInput(1, in, SizeOf(in) )
EndFunction

Type TInput
	Field iType:Int = INPUT_KEYBOARD
	
	'Keyboard structure
	Field key:Short
	Field wScan:Short
	Field dwFlags:Int
	Field time:Int
	Field dwExtraInfo:Int
	Field _extra1:Int
	Field _extra2:Int
EndType


-Henri


Chalky(Posted 2016) [#7]
Wow - neatly wrapped!


Fielder(Posted 2016) [#8]
nice!