With the help of some of the Cyberintelligensia, I am now able to use combinations of Ctrl+[some displayable key], Ctrl+Shift+[some displayable key], and Ctrl+Shift+Alt+[some displayable key] to add accented chars into a textbox.
The question and its answers are here.
However, there is still one recalcitrant combination. I used CodeCaster's suggestion to add a call to "Debug.WriteLine(keyData);" to see what in tarnation was being pressed (which keys). This works fine in most cases; for example, if I mash "Ctrl+Shift+E" it reports:
ControlKey, Control
ShiftKey, Shift, Control
E, Shift, Control
So it is responding as I expect, and enters a "É" in the textbox. That technique helped me to see what was needed to respond to the "!" character (D1).
However, there is one key combination that it is not discerning, namely "Ctrl+Shift+N" (Ctrl+N works). When I press "Ctrl+Shift+N" the Output window reports:
ControlKey, Control
ShiftKey, Shift, Control
IOW, it's missing an expected "N", and so nothing is added to the textbox ("Ñ" should be added).
This is the only case that fails; all the other key combinations work.
Ctrl+N does work. I see "ñ" in the textbox and get:
ControlKey, Control
N, Control
...in the Output window.
Why is the "N" in the Ctrl+Shift+N chord not "heard" and how can I rectify this?
This is the code that I have now:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
Debug.WriteLine(keyData);
if (this.ActiveControl != null && this.ActiveControl is TextBox)
{
string replacement = "";
TextBox tb = (TextBox)this.ActiveControl;
bool useHTMLCodes = checkBoxUseHTMLCodes.Checked;
// ...
// N
if (keyData == (Keys.Control | Keys.N))
{
replacement = useHTMLCodes ? "ñ" : "ñ";
}
else if (keyData == (Keys.Control | Keys.Shift | Keys.N))
{
replacement = useHTMLCodes ? "Ñ" : "Ñ"; // not working
}
// ...
if (replacement != "")
{
tb.SelectedText = replacement;
return true;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
As mentioned, everything works except the code to trap Ctrl+Shift+N, which should emit "Ñ".
UPDATE
I added this:
tb.ShortcutsEnabled = false;
...from here but it doesn't help matters.
UPDATE 2
An odd thing is that the Ctrl+Shift+N keyboard shortcut to open Notepad no longer works on my desktop (where I am working with the utility under discussion), but it does work in a remote desktop session (where I work on Sharepoint stuff).
Is the remote desktop connection really intercepting keystrokes on the desktop?
Even when logged off from the remote desktop session, though, the "blind spot" (Ctrl+Shift+N) remains within this desktop utility.