Using API to press a key

BlitzMax Forums/BlitzMax Programming/Using API to press a key

plash(Posted 2007) [#1]
I'm looking for something to programmically press a keystroke. I have not been able to find anything on Google (yet).
Can anyone help me?


Gabriel(Posted 2007) [#2]
What are you trying to fool? BlitzMax or the OS?

I think the correct term ( or *one* correct term, anyway ) is synthetic keyboard events, but I'm not sure if it's even possible at the OS level.


plash(Posted 2007) [#3]
I'm not trying to fool anything, I'm trying to create a macro system, you can record keyboard and mouse events, then play them back, I just want to be able to do something like this, only for the keyboard.


Who was John Galt?(Posted 2007) [#4]
I have a code example in the archives that clicks the mouse using Windows' SendInput function. You could modify this to insert keyboard events. Do a search for MSDN + Sendinput on google.


Who was John Galt?(Posted 2007) [#5]
Alternatively try a search for "AutoIT" on these forums. It may be of use I'm told.


plash(Posted 2007) [#6]
While searching for what nomen luni told me to, I found this. Now I just need to get all the variables for the keys. I dunno where y'all come up with all these api variables, but I'd sure like to get them for this.


plash(Posted 2007) [#7]
Found the variables, source




plash(Posted 2007) [#8]
I'm getting this error:
Compile Error: Missing type specifier

on the dwFlags variable for keybd_event function.

I searched MSDN to find the type for this and it is a "DWORD", however I noticed that DWORD is not a valid variable type in Max.
Does anyone know what the Max equivalent to a DWORD is?


Who was John Galt?(Posted 2007) [#9]
DWord is a double word=2*16 bits, which is a an unsigned long in Blitz I think (or a long will do).

Would you consider sticking your function in the code archives when it's done? Could be useful for me! : )


plash(Posted 2007) [#10]
Here is the completed version, please post bugs and improvements.

Virtual Keys


Who was John Galt?(Posted 2007) [#11]
OK thanks Plash!


plash(Posted 2007) [#12]
No problem.