In data entry form, I want users can not loose control if they are using backspace, arrow keys only the can move by using <Enter>, <Tab> or <Shift+Tab>.
In short: I wouldn't change the arrow key behaviour. Users should learn to use End or Pos1/Home to position on the start or end of a textbox instead of holding down left/right arrow key and wait, and to delete the whole box, use CTRL+A, then DEL (once) and that's even just one DEL or backspace, if you set SelectOnEntry = .T.
So even in regard to backspace I disagree, it's the users, who are doing this wrong. Users holding down keys and then complaining about what happens are more of a nuisance, because they should know better.
If you still want to go for that, you can take the keypress solutions and not only catch keycode 127 for backspace, but also arrow key codes, and you can make the suppression depend on textbox.SelStart being 0 (pos1) or this.value.length (end) and also cause the bell sound via ? chr(7) in case this keypress happens at these positions.
I wouldn't go for any of the solutions in the valid event, because the usage of the textbox can be key input and mouse and checking lastkey() even in conjunction with the cursor position in Selstart can give wrong results here. In keypress you know it's the actual key press right now.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.