Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console beep character code - wrong number?

ASCII character code 0x07 is a beep character.

Opening CMD and clicking ALT + 007 yields :

enter image description here

And when I click ENTER - I hear a beep. This is fine.

I've searched how to add a beep in the end of a batch file, and I found that this is the solution : (I'm pasting it as an image becuase SO doesn't show the round bullet after editing) :

enter image description here

This does work and does make a sound. When examined with a HEX viewer (with beyond compare) on ECHO, the round bullet is:

enter image description here

But if I manually add ALT+7 to the document , I see this:

enter image description here

Which is a 95 as a hex - and it's not a Beep. In addition, I went to the working batch file and added a new line with my ALT+7 :

enter image description here

But looking via HEX viewer :

enter image description here

Question:

I'm a bit confused. Clicking Alt+65 does yields A everywhere.

So why does the beep different and doesn't work when saved in Windows GUI?

In the console, if I click ALT+007 I get ^G (it does beep), but when I click ALT+7 I get the circle, which is not a beep:

Here are both:

enter image description here

Another interesting observation via notepad++ :

enter image description here

I think it's related to encoding, etc, but I don't understand the inconsistency.

like image 782
Royi Namir Avatar asked Oct 29 '22 04:10

Royi Namir


1 Answers

I have a workaround to suggest. Put this in your script:

forfiles /p "%~dp0" /m "%~nx0" /c "cmd /c echo 0x07"

For every file in your script's directory matching your script's filename (e.g. 1 time), it will echo ASCII character 7, and will make noise. From the forfiles /? documentation:

To include special characters in the command line, use the hexadecimal code for the character in 0xHH format (ex. 0x09 for tab). Internal CMD.exe commands should be preceded with "cmd /c".

forfiles is a handy utility to abuse whenever you need a non-printable or extended character.


As for my speculation for why Alt+007 doesn't behave as expected, I believe the console works on a different codepage from windowed applications (console = 437, windowed = 1252 for en-US, IIRC). I've struggled with this issue as well for reasons, ultimately resorting to hard coding the symbols used for console characters 1 through 31 in that JavaScript project.

like image 191
rojo Avatar answered Nov 09 '22 07:11

rojo