Is there an altgr modifier for SendKeys.Send

1 day ago 1
ARTICLE AD BOX

I'm writing a simple little winforms program that takes a text from a textbox and types it out one character at a type using the SendKeys.Send method. The problem is that the modifier in the string input that represents the alt key is for the left alt key and not the altgr key, so I can't write characters that are produced by the combination altgr plus another key press. Is there a way to force the right alt key instead of the left one?

private void startButton_Click(object sender, EventArgs e) { Thread.Sleep(3000); for (int i=0; i<toType.Text.Length; i++) { SendKeys.Send(charToKeystroke(toType.Text[i])); Thread.Sleep(150); } } string characters = ".-,"; private string charToKeystroke(char c) { string stroke = ""; if ((char.IsLetter(c) && !char.IsUpper(c)) || char.IsDigit(c) || characters.Contains(c)) { return "" + c; } else if (char.IsLetter(c) && char.IsUpper(c)) { return "+"+(c+"").ToLower(); } else { switch (c) { case '(': return "+8"; case ')': return "+9"; case '{': return "%b"; case '}': return "%n"; case '[': return "%f"; case ']': return "%g"; case ';': return "%,"; case '<': return "%í"; case '>': return "%y"; case '=': return "+7"; case '!': return "+4"; case '$': return "%é"; case '\n': return "{ENTER}"; case '\t': return "{TAB}"; case '+': return "{PLUS}"; case '-': return "{MINUS}"; case '/': return "{DIVIDE}"; case '*': return "{MULTIPLY}"; case '&': return "%c"; case '\'': return "+1"; case '"': return "+2"; case '|': return "%w"; case ':': return "+."; case '#': return "%x"; case '@': return "%v"; case ' ': return "{SPACE}"; } } return stroke; }

For example, with the code above I would expect to get to see a left curly bracket typed when the input is a '{', but instead, if I have a notepad in focus, the bold font style gets activated. (Hungarian keyboard layout)

Zoltán Király's user avatar

Read Entire Article