Keyboard test...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Keyboard test...

Post by Psychophanta »

Should be easely possible to add a directinput Keyboard funtion to examine and capture in memory all the complete keyboard status matrix and work with it?

It would avoid to call lot of times to KeyboardPushed() function inside a loop.

Thanx :)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

euh, isn't that what's currently happening? examinekeyboard() fills the memory and then you check the dfferent keys? or am i missing the point here?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I just requested for a keyboard function which dump the keyboard status to a 128-bit variable.
A 128-bit variable (memory address) would be enough for all keyboard keys (a bit, a key) to see whether a key is pushed or not.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

ah... didn't get it at first :-)

i think a simple directx call should do the job (though don't ask me how to do it, i do not have a clue)

:P
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> I just requested for a keyboard function which dump the keyboard
> status to a 128-bit variable.

The GetKeyboardState API is supposed to do just that, but I haven't
tried it -- maybe you can get this VB example working in PureBasic:

http://www.mentalis.org/apilist/GetKeyboardState.shtml
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Re: Keyboard test...

Post by Doobrey »

Psychophanta wrote:Should be easely possible to add a directinput Keyboard funtion to examine and capture in memory all the complete keyboard status matrix and work with it?
No need for DirectInput.. Use GetKeyboardState_() API command.
According to API Guide, "The GetKeyboardState function copies the status of the 256 virtual keys to the specified buffer."

Dim Keys.b(256)
GetKeyboardState(@Keys[0])
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

This should work:

Code: Select all

*mem=AllocateMemory(0,256,0)
If *mem 
  GetKeyboardState_(*mem)
  For *t=*mem To *mem+255
    Debug PeekB(*t)
  Next
EndIf
however, I've tried and GetKeyboardState() is too slow. It is a weak :cry:

Thanks anyway you Doobrey and PB.

Doobrey, i guess you can't assure that an array has its elements contiguous in memory.

For those interested here is a complete list for that which Microsoft calls Virtual Key Codes: http://msdn.microsoft.com/library/defau ... _codes.asp
Post Reply