Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape Becomes Ctrl-Z - but why?

Tags:

vb6

I am currently maintaining a VB6 app, but have very little knowledge of VB6. I have come across a bit of code which has me perplexed.

Private Sub Form_KeyPress(KeyAscii As Integer)
  KeyAscii = Asc(UCase(Chr(KeyAscii)))
  If KeyAscii = 27 And TypeOf Me.ActiveControl Is TextBox Then
      KeyAscii = 0
      SendKeys "^Z"
  End If
End Sub

Here's what I know: the code is invoking a keypress of Ctrl+Z when the escape button is pressed. Here's what I don't know: why? I debugged through after clicking escape, and apart from the contents of the if statement being run through, it doesn't do much that I can percieve (apart from the fleeting display of a cursor).

Does anyone know the importance of this? i.e. sending a Ctrl+Z keypress combination.

like image 807
onefootswill Avatar asked Nov 26 '25 10:11

onefootswill


2 Answers

A Ctrl+Z is the end-of-file character for DOS-based systems unlike the (usually, though configurable) Ctrl+D in UNIX-like systems.

However, I think it more likely in this case to be an undo command, given that it's happening within a textbox.

That would be my first guess, that you need to send that keystroke to revert any changes you've made.

One way to test that theory would be to make a change in the textbox, then do the Ctrl+Z to see if it reverts.

Of course, a given application is free to interpret the keystroke in any way it sees fit. You should probably look into the code to see what Ctrl+Z is meant to do.

like image 157
paxdiablo Avatar answered Nov 29 '25 00:11

paxdiablo


The Ctrl+Z keystroke will be passed on to the control with keyboard focus. Some controls have limited support for undoing recent edits: particularly the textbox.

So this is probably a quick-and-dirty way to associate a non-standard key (Esc) with the action of undoing the latest edit. You won't find any more source code for the keypress in the VB6 code, because the keypress is actually being handled by the Windows controls.

like image 23
MarkJ Avatar answered Nov 29 '25 00:11

MarkJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!