Can I use getch from msvcrt.dll?

Blitz3D Forums/Blitz3D Beginners Area/Can I use getch from msvcrt.dll?

pimpom(Posted 2007) [#1]
Hi, I want to use getch + kbhit from msvcrt.dll, but for some reason I only get 0, so probably I'm doing something really wrong. Any ideas?

While Not KeyHit (1)
	Delay (100)
	;result=CallDLL( "msvcrt.dll","kbhit") ;result was always 0, tried too with "_kbhit"
	result=CallDLL( "msvcrt.dll","getch") 
	DebugLog result
Wend


Thanks.


Mortiis(Posted 2007) [#2]
why dont you use waitkey() ?


Mortiis(Posted 2007) [#3]
Anyway, you need a .decls file in order to use a dll.

Take a look at This!


pimpom(Posted 2007) [#4]
Hi, thanks for your reply. Waitkey will work for kbhit, just wanted to try that dll thing.

As for getch, I want to use it as it doesn't pauses the loop and I don't know which key the user will press, but I need to know afterwards.

I wrote following .decls:
.lib "msvcrt.dll"
getch#():"_getch"

and for code:


While Not KeyHit (1)
	WaitKey()
	result=getch()
	DebugLog result
Wend


but still not returning valid value (geting -2147483648) . Is there something else I am missing?

Thanks


b32(Posted 2007) [#5]
It could be the conversion from float to integer ? Maybe you could try getch%():"_getch" instead in the .decls


Mortiis(Posted 2007) [#6]
You can use something like this to get which key is pressed.

pressedKey = GetKey()



pimpom(Posted 2007) [#7]
Hi, thank you both. I went the GetKey route. My only concern is that i wasn´t able to use the .decls file. Indeed getch shall return ints, buts for some reason jsut getting -1 now. anyhow Getkey() shall do the trick.

Thanks again.