2

I'm trying to send the period "." character with both SendKeys.Send and SendKeys.SendWait methods (and in both "." and "{.}" forms) and it just seems to not work (i.e. application hangs).

I'm having trouble just with the "dot" character, since other symbols are sent over without issues.

I also tried passing the Keys.OemPeriod enum value but what I got was to send either its string representation "OemPeriod" or numerical value 188, depending on the method I used (cast or ToString) since Send/SendWait accept just a String value.

PS If you're wondering, I'm implementing an Excel-like behaviour of converting the Keys.Decimal (numpad period) value to the current decimal separator, using a IMessageFilter object.

EDIT After some tests I found that it works if a keyboard layout with a comma on the "Del" button of the numpad is set. Seems like a conflict occurs when sending a "." and it is both Keys.OemPeriod and Keys.Decimal, but I need to discriminate between them to implement a consistent behaviour.

EDIT2

Here is some sample code of my filter prototype

Public Class DecimalKeyFilter
   Implements IMessageFilter

   Private Const WM_KEYDOWN As Integer = &H100

   Public Function PreFilterMessage(ByRef m As Message) As Boolean _
      Implements IMessageFilter.PreFilterMessage

      If (m.Msg <> WM_KEYDOWN) Then Return False

      Dim key As Keys = DirectCast(m.WParam.ToInt32() And Keys.KeyCode, Keys)
      If (key <> Keys.Decimal) Then Return False

      Dim separator As String = CurrentCulture.NumberFormat.NumberDecimalSeparator
      SendKeys.Send(separator)
      Return True
   End Function
End Class

EDIT3

For the sake of completeness, I solved the problem by calling the native SendInput function, which appears to be the SendKeys underlying Win32 API, and which accepts the Virtual Key codes directly in Short format. This strongens my doubt that a conflict is happening when a string representation that is mapped to multiple Virtual Keys is sent, which would render SendKeys a really poor API. Anyway, this is just my hypothesis, so any further explanation to this behaviour is welcome

bassfault
  • 154
  • 1
  • 7

0 Answers0