'How do text-editors recognize if the user wanted to type a number or the ascii value associated with it?

According to my current understanding:-

  1. All binary values are treated as equal by the system, and it is the task of the software (or the app) to interpret a binary value as text or image, etc. based on the context in which the app expects the data to be.
  2. When a key is pressed by the user, an event is fired by the system and any running application handles the event and gets the value of the key pressed.

Now, take for example the user presses the tab key.

Binary Value of the horizontal tab (if I'm not wrong) -

00001001

When this binary value is converted into its decimal equivalent, we get “9” as the value.

Now my doubt[s] are:-

  1. How does the text editor recognize whether the value “9” or a horizontal tab is to be taken as the final value? In other words,
  2. How does the software know whether or not the decimal value needs to be converted to its ASCII character equivalent?
  3. Whether the tab key or the digit 9 key was pressed?
  4. How, or in what form, or with what details does the system fire an event for a keypress?

I would be glad if you could help me out (in simple terms, of course), and please do point out if I am mistaken at something.

Thank you!



Solution 1:[1]

Okay, I think you were mission on 2 pretty important details.

Here they are:-

  1. Different ASCII codes are present for all the digits (0 through 9) as well, and that there is a different key code for the digit "9" and the decimal value "9", which, as @ggorlen pointed out, is the tab key.
  2. Most of the applications always take in the ASCII (or any other type of character encoding) equivalent, instead of the decimal equivalent of a keypress's binary value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1