Retund scan code
Blitz3D Forums/Blitz3D Beginners Area/Retund scan code
| ||
How can I do I know waitkey() will give ASCII one but I want it to return the scancode value |
| ||
Chr$(ascii_value) = scancode valuePrint " The character for ASCII value 65 is: " + Chr$(65) Waitkey() |
| ||
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 |
| ||
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. |
| ||
LOL :) i didnt read the topic very good since i didnt have much time.. sorry |
| ||
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. |
| ||
does this help:?Repeat key=GetKey() If key txt$=txt$+Chr(key) EndIf Text 10,10,txt$ Until KeyDown(1) End |
| ||
nope |
| ||
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!) |
| ||
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. |
| ||
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? |
| ||
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. |
| ||
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. |