When using SendKeys.Send()
of System.Windows.Forms
to send a caret ^
SendKeys.Send ("{^}")
it will send an ampersand &
instead.
Why?
When using SendKeys.Send()
of System.Windows.Forms
to send a caret ^
SendKeys.Send ("{^}")
it will send an ampersand &
instead.
Why?
I solved this for a german keyboard layout.
The Problem is that some keys are hardcoded like this:
static SendKeys()
{
keywords = new KeywordVk[49]
{
...
new KeywordVk("+", 107),
new KeywordVk("%", 65589),
new KeywordVk("^", 65590) // this is a problem !
}
}
So the hack is to override the value of new KeywordVk("^", ...)
// fix caret, ^, circumflex on german keyboards
public static void FixSendKeys_Caret()
{
// SendKeys.keywords
var keywordsField = typeof(SendKeys)
.GetField("keywords", BindingFlags.NonPublic | BindingFlags.Static)
.GetValue(null) as IList;
// KeywordVk { keyword= "^", vk = xx }, should be at index 48
var keywordVk_Obj = keywordsField[48];
var keywordField = keywordVk_Obj.GetType().GetField("keyword", BindingFlags.NonPublic | BindingFlags.Instance);
// KeywordVk.vk
var vkField = keywordVk_Obj.GetType().GetField("vk", BindingFlags.NonPublic | BindingFlags.Instance);
if (keywordField.GetValue(keywordVk_Obj).ToString() != "^")
throw new Exception("wrong KeywordVk");
// SendKeys.keywords[48].vk = (int)Keys.Oem5;
// For german keyboards "^" = Keys.Oem5
vkField.SetValue(keywordVk_Obj, (int)Keys.Oem5);
// check if its correct
var getVal = vkField.GetValue(keywordVk_Obj);
}
Call this once before your SendKeys code
According to
https://www.experts-exchange.com/questions/28994144/SendKeys-caret-sends-ampersand.html
it's a localization issue.
Changing the keyboard layout from german layout to english layout should help.