getmouse() and getkey() alternatives.

BlitzMax Forums/BlitzMax Beginners Area/getmouse() and getkey() alternatives.

TrickyRic(Posted 2005) [#1]
i only purchased blitzmax today, the linux build, and must admit so far i'm impressed! however, it seems a few too many commands have been depricated and thus i'm having a little trouble porting some of my old win32 applications over...

the two functions bugging me the most (parden the pun) are getmouse(), and getkey(). for screensaver development these functions were pretty much a requirement in blitzbasic and blitz3d as conditions within the main loop. why have they been depricated from max? too many differences in the api of linux, mac, and windows maybe? whatever the reason, i need a solution! how do others check for mouse and keyboard input without having to check each individual key/button in one LONG statemente of or operators?

ty.


Robert Cummings(Posted 2005) [#2]
http://www.blitzwiki.org/index.php/Main_Page


Guide there shows the main differences between Blitz3D and Blitzmax - might help.


TrickyRic(Posted 2005) [#3]
hi.

thanks for the link but to be honest i'd already noticed it in the stickies <grin>. it helped me in other areas, such as the introduction of framework and import commands (kinda funny seing a c like structure in a basic interpretation, but what the hell it speeds compilation and execution up by unbloating scripts so...), but i can't find any reference to the above deprications.


JazzieB(Posted 2005) [#4]
Well, you have GetChar() to check keyboard input, although this is mainly keys with ASCII codes. If you want to check for all scancodes then you could use...

Function GetKey:Int()
  Local key:Int=-1
  For Local i:Int = 0 to 255
    If KeyHit(i) Then key=i;Exit
  Next
  Return key
End Function
Where -1 would indicate no key was pressed and anything else would return the key code (not the usual scancode) of the key.

I wouldn't have thought this necessary in a screensaver though, as I don't think that many people would press anything other then Space or Return to get out. Unless you have something else in mind.

As for the mouse, the 3 mouse buttons actually have key codes (or you could use the usual MouseHit or MouseDown). As for the movement, simply keep track of the last known X and Y co-ordinates and if they change the next frame you know the mouse has moved.

Hope that helps a little.


TrickyRic(Posted 2005) [#5]
theoretically looping through the keys would indeed do the same job as good ol' getkey, but in practice having to parse through so many functions and condition checks every single time the main loop loops a cycle would surely slow things down considerably? this is already a pretty resource hungry screensaver i'm porting over (hell its optimal resolution is 400x300 in a 16bit colour depth!).

whats more, being the freak that i am, i'm a sucker for tradition, and traditional screensavers take ANY mouse or keyboard input as a signal to close. why's this a problem? well put simply, not all mice are 2-3 button. more precisely, anyone who's played with the xorg/xf86 settings for the inputdevice section on a linux box will know that different systems map different buttons. the mx1000 is a great example of this - with a default config and no zaxismapping values, some of the buttons behave somewhat oddly...

now i have no knowledge of the workings behind the getkey() or getmouse() functions in previous blitz releases, but i'd assume at least getmouse() would offer something reliable enough to deal with this kind of scenario? a direct interface with the i/o buffers of the operating system perhaps? if so then looping through possible hits simply wouldn't be reliable enough for use in a traditional screensaver.

maybe i'm looking too deep into all this? i can be somewhat of a perfectionist at times...


REDi(Posted 2005) [#6]
maybe i'm looking too deep into all this?


:)

Graphics 640,480,16

Local mx = MouseX()
Local my = MouseY()

Repeat
	If GetChar() End
	If MouseHit(1) Or MouseHit(2) Or MouseHit(3) End
	If MouseX()<>mx Or MouseY()<>my End
Forever


That'll do it.


ashmantle(Posted 2005) [#7]
BlitzBasic and Blitz+ and Blitz3D all have functions for retrieving key states and mouse movement.

BlitzMax has this for keys:

GetChar();
if any key is pressed on the keyboard, blitzmax maintains a queue of them and GetChar() returns the character code or 0 if queue is empty.

Mouse:

MouseX() and MouseY() (MouseZ() for mousewheel)
they will return current position in relation to top-left corner of screen. Easy to write MouseMoved() function from this.

EDIT: bah, Papa Lazarou beat me to it ^^


REDi(Posted 2005) [#8]
Yeah, but i forgot MouseZ :)


TrickyRic(Posted 2005) [#9]
cheers guys, getchar() does the trick. surprised i didn't notice that in the command index actually, hehe.

still a little worried about mouse input though. without a generic function like the previous getmouse(), developers have to assume the use of a 1-3 button mouse... mine has 8 plus horizontal and verticle scroll...


Dreamora(Posted 2005) [#10]
Does not change anything as only 3 buttons and 3 axises are supported. (more were only supported in old Blitz through DirectInput)


TrickyRic(Posted 2005) [#11]
guess i'll declare this as solved then :). cheers guys.