• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Mapping Delete Key to ord("\x7F") For Use With keyboard_lastchar

Anixias

Member
Hi, all.

I'm attempting to make a robust textbox system using keyboard_lastchar. This works automatically with backspaces as long as you handle "\b" as removing the character the cursor is on rather than literally adding the character "\b" to the string. It also automatically works with holding backspace down: it deletes a character, then after a short time, rapidly deletes characters until the key is released.

I was perplexed to discover that the Delete key does not affect keyboard_lastchar in any way, yet Ctrl+F maps to \x06 where just F maps to \x46 and f maps to \x66. I found out that Ctrl+Backspace is the non-breaking space character \x7F. I decided I would use that to simulate the Delete key, which would automatically work the same way Backspace had. However, calling keyboard_set_map(vk_delete, ord("\x7F")) does not cause the delete key to affect keyboard_lastchar.

I just find it odd that the Delete key (and Home, Insert, etc.) have no affect over keyboard_lastchar, even if you map the key to some other unicode value. I tested it further by mapping vk_delete to vk_backspace, but still no effect. keyboard_string obviously does not detect Delete either. I thought about using keyboard_key to artificially set keyboard_lastchar to "\x7F" but, as far as I'm aware, this would not cause the automatic behavior of simulating once, waiting a short time, and then simulating multiple times until key release.

Now, of course, I can just artificially add that functionality in myself, but I wanted to check with the forum to see if anyone had any light to shed on the issue before I do it the manual way.
 

gnysek

Member
keyboard_lastchar
Stores the last character pressed (as a string).
I think that Delete key isn't a char.

Also, for keyboard_string, Delete won't work too, as there's no text after that string, and Delete key task is to delete text on right of current edition place (which I think in that case is end of string).

I've made several textbox systems, and to use Delete key, there was need to add some kind of cursor/caret, but then I also needed to split text into two strings - before and after caret. But i just used normal keyboard events to handle Delete this way (with some variable locking delete key for few frames after pressing, so text isn't wiped out too fast for user - otherwise in 60 FPS game a 60 letters can be deleted in one second).
 

Anixias

Member
Yeah, it appears that Delete doesn't produce any chars, and can't be simply mapped. It looks like the only option is to manually add in the functionality.

Instead of storing two separate strings (before and after), I usually just store the position of the insertion point. This is also helps massively when you want multiple characters to be selectable with the mouse or Shift+Arrow Keys, for example.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Just saying, there is a keyboard_lastkey.

Edit: I'm not sure if you're somehow limited to using just keyboard_lastchar, but since the key you're trying to check is not a character, that effort is headed nowhere.
As for Del not affecting keyboard_lastchar... it working like a one-char-wide keyboard_string is not the intention, so that's not how it works.
 

Anixias

Member
Just saying, there is a keyboard_lastkey.
I'm aware. However, it doesn't help with the built-in Windows functionality of a single key pulse followed by a delay and then a rapid firing of the key if the key is held down. It simply returns the key that was last pressed.
(Post-solved: ^I was literally wrong, it DOES have that built-in functionality.)

it working like a one-char-wide keyboard_string is not the intention, so that's not how it works.
Well, Del doesn't appear on keyboard_string either, anyway. And yes, I understand that they are quite different, as Ctrl+F produces a code unique from 'F' and 'f' with keyboard_char but just 'f' with keyboard_string. And no, I'm not limited to using keyboard_char, just thought I'd try it out as I've never needed to use it before and it is quite handy so far.

I was only looking to see if anyone had a way of mapping a key to produce a char to keyboard_string or keyboard_lastchar but that isn't possible, it seems. I will just hard-code the functionality.

SOLVED: OH my god I am dumb. I should've just tested keyboard_lastkey the same way I tested keyboard_lastchar. Guess what? The built-in Windows functionality is there for it too... Just set it to vk_nokey after reading from it and it will do exactly as keyboard_lastchar does. You can just use this to set keyboard_lastchar to "\x7F" if it is emitting vk_delete. I am an idiot.
 
Last edited:
Top