SendKeys Problem(s): SendKeys(str) drops period; Tone configurable?

  • Thread starter Thread starter Joe W Larson
  • Start date Start date
J

Joe W Larson

Implementing the latest SendKeys OpenNETCF source has resulted in 2 strange
bugs. Any ideas appreciated.

Platform: C# on CE.NET 4.2 (Teklogix 7535)

1. If the string contains a period, SendKeys(str) drops the period
(ABC.123 -> ABC123). Does anyone know how to get the period to come through
SendKeys?

2. On every SendChar, the device emits a screech/audible tone. Is this
configurable-- can it be turned off?



Thanks,

Joe Larson
 
1. I don't see any explanation of that. Can you step into it and see where
the period is being dropped?

2. I think that it's just the key click that you're hearing. If so, you can
turn that off in the Control Panel's Volume & Sounds applet. If that's not
it, I can't guess.

Paul T.
 
Paul G. Tobey said:
1. I don't see any explanation of that. Can you step into it and see where
the period is being dropped?

The relavent code is this:

-------------------
public static void Send(string keys)
{
byte [] mods = new byte[3];

char ch;
int pos;
int index = 0;
byte group = 0;
while(index < keys.Length)
{
ch = keys[index];
switch(ch)
{
case '(': // start group
if (group > 3) throw new ArgumentException("Nesting error.");
group++;
SetMods(mods, 4, group);
break;

case ')': // end group
if (group < 1) throw new ArgumentException("'(' is missing.");
CancelMods(mods, group);
group--;
break;

case '+':
if (mods[SHIFTPOS] != 0) throw new ArgumentException("Invalid SendKey
string.");
mods[SHIFTPOS] = 4;
SendKey(SHIFTVK, KEYEVENTF_KEYDOWN);
break;

case '^':
if (mods[CONTROLPOS] != 0) throw new ArgumentException("Invalid
SendKey string.");
mods[CONTROLPOS] = 4;
SendKey(CONTROLVK, KEYEVENTF_KEYDOWN);
break;

case '%':
if (mods[ALTPOS] != 0) throw new ArgumentException("Invalid SendKey
string.");
mods[ALTPOS] = 4;
SendKey(ALTVK, KEYEVENTF_KEYDOWN);
break;

case '~': // ENTER key
SendChar(13, mods);
break;

case '{':
{
index++;
if ((pos = keys.IndexOf('}', index)) < 0) throw new
ArgumentException("'}' is missing.");
string t = keys.Substring(index, pos - index);
if (t.Length == 0) // {}}?
{
index++;
if (keys.Length > index && keys[index] == '}')
SendChar((byte)'}', mods);
else
throw new ArgumentException("'{}' is invalid sequence.");
}
else
{
int count;
index += t.Length;
string [] s = t.Split(new char[]{' '});
if (s.Length > 2) throw new ArgumentException("Incorrect string in
the {...}");
if (s.Length == 2)
{
t = s[0];
count = Convert.ToInt32(s[1]);
}
else
count = 1;

int vk = MatchKeyword(t);
if (vk < 0) // key has not been found
{
if (t.Length == 1) // is it {+}, {~}, {^}, etc.
vk = (byte)t[0];
else
throw new ArgumentException("Keyword '" + t + "' has not been
found.");
}

for(int i = 0; i < count; i++)
SendChar((byte)vk, mods);
}
break;
}

default:
SendChar((byte)ch, mods);
break;

}

index++;
}

CancelMods(mods, 4);
}
---------------------------------------


It does not appear to do anything with periods per se.

We are worried this is a device specific problem.
 
That's what I'm saying. Step into it and see what's actually going on.
Maybe there's a off-by-one error in some substring extraction operation or
something. It's going to be way easier to debug it than it is to just spot
it with nothing to go on.

Paul T.

Joe W Larson said:
Paul G. Tobey said:
1. I don't see any explanation of that. Can you step into it and see where
the period is being dropped?

The relavent code is this:

-------------------
public static void Send(string keys)
{
byte [] mods = new byte[3];

char ch;
int pos;
int index = 0;
byte group = 0;
while(index < keys.Length)
{
ch = keys[index];
switch(ch)
{
case '(': // start group
if (group > 3) throw new ArgumentException("Nesting error.");
group++;
SetMods(mods, 4, group);
break;

case ')': // end group
if (group < 1) throw new ArgumentException("'(' is missing.");
CancelMods(mods, group);
group--;
break;

case '+':
if (mods[SHIFTPOS] != 0) throw new ArgumentException("Invalid SendKey
string.");
mods[SHIFTPOS] = 4;
SendKey(SHIFTVK, KEYEVENTF_KEYDOWN);
break;

case '^':
if (mods[CONTROLPOS] != 0) throw new ArgumentException("Invalid
SendKey string.");
mods[CONTROLPOS] = 4;
SendKey(CONTROLVK, KEYEVENTF_KEYDOWN);
break;

case '%':
if (mods[ALTPOS] != 0) throw new ArgumentException("Invalid SendKey
string.");
mods[ALTPOS] = 4;
SendKey(ALTVK, KEYEVENTF_KEYDOWN);
break;

case '~': // ENTER key
SendChar(13, mods);
break;

case '{':
{
index++;
if ((pos = keys.IndexOf('}', index)) < 0) throw new
ArgumentException("'}' is missing.");
string t = keys.Substring(index, pos - index);
if (t.Length == 0) // {}}?
{
index++;
if (keys.Length > index && keys[index] == '}')
SendChar((byte)'}', mods);
else
throw new ArgumentException("'{}' is invalid sequence.");
}
else
{
int count;
index += t.Length;
string [] s = t.Split(new char[]{' '});
if (s.Length > 2) throw new ArgumentException("Incorrect string in
the {...}");
if (s.Length == 2)
{
t = s[0];
count = Convert.ToInt32(s[1]);
}
else
count = 1;

int vk = MatchKeyword(t);
if (vk < 0) // key has not been found
{
if (t.Length == 1) // is it {+}, {~}, {^}, etc.
vk = (byte)t[0];
else
throw new ArgumentException("Keyword '" + t + "' has not been
found.");
}

for(int i = 0; i < count; i++)
SendChar((byte)vk, mods);
}
break;
}

default:
SendChar((byte)ch, mods);
break;

}

index++;
}

CancelMods(mods, 4);
}
---------------------------------------


It does not appear to do anything with periods per se.

We are worried this is a device specific problem.
 
In fact, this problem is the same on a HP iPaq w/ Pocket PC 2003. So it is
not device specific.
 
No surprise there. I've sent keys using my own wedging code, which uses the
same functions as the OpenNETCF implementation of SendKeys(), and I'm sure
that '.' works just fine.

Paul T.
 
Back
Top