Anyone used the Insert key?
Dr_Acula
Posts: 5,484
I thought I would add the insert key to a text editor but it is proving quite difficult and I've very much appreciate some help!
Ok, first thing was a small bug on the keyboard where I couldn't get the escape key to work. I think this might be a related problem so I'll describe the experiments so far:
This is the comment section from the keyboard object:
and it is supposed to send CB for escape and CA for insert. The code that does this is here
but I seemed to get 02 for escape. So I changed this one little line to send 1B instead of CB and now escape works.
Ok, if that works, then I figured the same thing should work for Insert. I took this line word $CAE0 '70 Insert (0) and changed it so it (I thought) would return a character A - word $0041
But it doesn't return anything. If I go back to $CAE0 it returns $02
I'm also confused by the codes that come back. Insert is CAE0 and the scancode for this key is E0,70 http://www.computer-engineering.org/ps2keyboard/scancodes2.html so I figured that because End is E0,69 on that website it would be in the code too, but it is $C5E1
Anyway, the comment code at the top of this thread makes it seem that it should be quite simple and should return some numbers C0 to CF depending on the key pressed. I can't seem to find any code that replicates this explicitly, and the closest is this table. But the table appears to only return C0 to C9. CA (Insert) and CB (Escape) don't seem to work.
Maybe the insert key is not used by most people so perhaps this has never come up as an issue. Any help here would be most appreciated.
Ok, first thing was a small bug on the keyboard where I couldn't get the escape key to work. I think this might be a related problem so I'll describe the experiments so far:
This is the comment section from the keyboard object:
'' C0 Left Arrow '' C1 Right Arrow '' C2 Up Arrow '' C3 Down Arrow '' C4 Home '' C5 End '' C6 Page Up '' C7 Page Down '' C8 Backspace '' C9 Delete '' CA Insert '' CB Esc '' CC Apps '' CD Power '' CE Sleep '' CF Wakeup
and it is supposed to send CB for escape and CA for insert. The code that does this is here
word $C5E1 '69 End (1) word $0000 '6A word $C0E4 '6B Left (4) word $C4E7 '6C Home (7) word $0000 '6D word $0000 '6E word $0000 '6F word $CAE0 '70 Insert (0) word $C9EA '71 Delete (.) word $C3E2 '72 Down (2) word $00E5 '73 (5) word $C1E6 '74 Right (6) word $C2E8 '75 Up (8) word $00CB '76 Esc word $00DF '77 NumLock word $00DA '78 F11 word $00EC '79 (+)
but I seemed to get 02 for escape. So I changed this one little line to send 1B instead of CB and now escape works.
word $001B '76 Esc
Ok, if that works, then I figured the same thing should work for Insert. I took this line word $CAE0 '70 Insert (0) and changed it so it (I thought) would return a character A - word $0041
But it doesn't return anything. If I go back to $CAE0 it returns $02
I'm also confused by the codes that come back. Insert is CAE0 and the scancode for this key is E0,70 http://www.computer-engineering.org/ps2keyboard/scancodes2.html so I figured that because End is E0,69 on that website it would be in the code too, but it is $C5E1
Anyway, the comment code at the top of this thread makes it seem that it should be quite simple and should return some numbers C0 to CF depending on the key pressed. I can't seem to find any code that replicates this explicitly, and the closest is this table. But the table appears to only return C0 to C9. CA (Insert) and CB (Escape) don't seem to work.
Maybe the insert key is not used by most people so perhaps this has never come up as an issue. Any help here would be most appreciated.
Comments
I get keycodes from the whole range of $C0..$CF although I don't use $CD..$CF
Attached are the source files for the keyboard driver and window editor
Addit - I found a combo mouse key driver, and changing
word $CAE0 '70 Insert (0)
to $0041
returns nothing, so I can replicate one part of the bug.
Where would I get combokey.spin?
I think the part that processes the table is here (though there are a few other calls to 'table')
What I can't quite understand is how a 4 byte value in 'table' gets converted into a 4 byte value that is returned, where the returned value always is $00nn but the value in 'table' sometimes has 00nn and sometimes nnnn.
There is something cunning going on here...
I just found something
This prints out 41 (ascii A) when you press Insert. I think what is happening is that for that group of 10 keys (insert/delete/home/end/pageup/pagedown/arrowup/arrowdown/arrowleft/arrowright), the high byte of the word is the value returned, and for most other keys it is the low byte. My working theory is that the values like 'EA' and 'E2' for the lower byte for delete and down, are red herrings.
This theory could make sense because those 10 keys are different in that they return two byte codes (three on key up). It could also explain why the Insert key on the keypad works fine but not the Insert key in that group of 10.
Back to debugging...
Addit: yes, that is it. Change the high byte for that group of 10, change the low byte for pretty much every other key. Insert now works and I can map it to ^I for Wordstar or ^N for Vedit, or anything else as required.
Thanks ++ for the help and words of encouragement. Where this is heading is a practical text editor on the propeller that is fast to load, fast to run, and can even do clever things like auto-indentation for C.