Retund scan code

Blitz3D Forums/Blitz3D Beginners Area/Retund scan code

Agamer(Posted 2004) [#1]
How can I do I know waitkey() will give ASCII one but I want it to return the scancode value


cermit(Posted 2004) [#2]
Chr$(ascii_value) = scancode value

Print " The character for ASCII value 65 is: " + Chr$(65)
Waitkey()



BlackJumper(Posted 2004) [#3]
You could write a conversion function... probably based on the position of the character in a string.

here is a snippet...
Repeat
While Not value 
value=GetKey() 
Wend
FlushKeys

      KeyPressed = ConvertToScan(value)
	  Print "ASCII Value was " + value 
	  Print " ... which is key : " + Chr$(value)
	  Print " ... which has scan value: " + KeyPressed
	  Print

If value = 27 Then EscPressed = True 

value = 0
Until EscPressed


Function ConvertToScan(Pressed)
         If Instr("qwertyuiop", Chr$(Pressed) )> 0 Then
            Pos% = Instr("qwertyuiop", Chr$(Pressed) ) + 15
         EndIf
		 ; more tests for other rows....
     	 Return Pos%
End Function



Zethrax(Posted 2004) [#4]
Chr$(ascii_value) = scancode value


Keyboard scancodes and ASCII values are not the same thing, so that won't do the job.

KeyDown( scancode ) and KeyHit( scancode ) are the standard commands to do keypress detection using scancodes. They both require that you specify the scancode you want to check for between the parenthesis, and they return a true or false result ( 1 or 0) depending on whether they scancode key is pressed or not. Check the docs for more info.


cermit(Posted 2004) [#5]
LOL :) i didnt read the topic very good since i didnt have much time.. sorry


_PJ_(Posted 2004) [#6]
I'm sure there was some code in the archives dealing with redefineable keys etc. that would be easier to modify if you wish to compare scancodes with ASCII. Otherwise it's quite laborious because scancodes have no connection with characters at all.


Jeppe Nielsen(Posted 2004) [#7]
does this help:?
Repeat

key=GetKey()
If key
	txt$=txt$+Chr(key)
EndIf

Text 10,10,txt$

Until KeyDown(1)
End



Agamer(Posted 2004) [#8]
nope


_PJ_(Posted 2004) [#9]
OKay what I meant was:

Modify This to convert scancodes to whatever you desire - The boring bit's been done for ya by Edzup (thanks!)


Zethrax(Posted 2004) [#10]
The best and fastest way to convert scancodes to ASCII codes, or visa versa, is to simply use an array as a lookup table and use the scancode or ASCII code you're converting from to index the array, which should hold the corresponding scancode or ASCII code being converted to in the indexed slot.


CloseToPerfect(Posted 2004) [#11]
I think he want to detect what key is pressed and return a scancode value for it, is that possible without ckecking true/false keydown values for all scancodes?


Zethrax(Posted 2004) [#12]
I think GetKey() will do that. It returns ASCII values, not scancodes, though, and not all keys have ASCII values so it won't detect them all. It should be possible to convert it to a scancode using the method I described in my last post, if it's absolutely necessary to do that.


_PJ_(Posted 2004) [#13]

I think he want to detect what key is pressed and return a scancode value for it, is that possible without ckecking true/false keydown values for all scancodes?



There must be a simpler way to do this, with a For/Next Loop which loops through all the scancodes, and the use of KeyDown and True/False.