Yes, JavaScript can be used to catch input events, which is what those editors End User suggested does to do things with shortcuts.
Writing a tutorial for this would take some time, so I'll just point you to some links for now. You can try QuirksMode (link in signature) for a good reference on dealing with events across various browsers. Once you have caught the event and know it's time to insert say
or
around the selected text, you need to get the document's selection. Depending on the browser, t's a call to a method of the window or document object. You might also have to convert that selection to a range object, again depending on the browser. The range/selection object can then be manipulated and wrapped in your tag.
Looking at one of the WYSIWYG editors with less features might be a good idea as you can take ideas from already working code.