serial post Issues with app behind other apps

This is the dataAvailable from an app. The app allows me to control the mouse on the screen for other applications with a remote button device via USB. When the xojo app is in front, I cannot get an error. When the xojo app is behind the app I am controlling, after some random amount of data input, the xojo app stops controlling the front application. If I click back on the xojo app and then back on the application I am controlling, things start working correctly.

An observation I made is that if I put a text pane on my xojo app that shows the single byte received remotely via the serial port, the text pane will show a single byte of received data per USB data input.

RxDataE.text = str(RxData)

But when the problem occurs, I can look at the RxDataE text pane and see a lot of values from the button input received from USB. There should not be allowed more than 1 byte displayed. Maybe I am not receiving the data correctly from serial?

Any suggestions appreciated.

[code] RxData=Me.ReadAll
p=new PresskeyMBS
p.mouseclick(false)
Select Case val(rxData)

RxDataE.text = str(RxData) // see what button is being pressed and sent to the app via USB.

case 0
case 1
//Move Mouse to position in MousePosX text pane and MousePosY text pane
ClearFocus
call RemoteControlMBS.MacMoveMouse(val(MousePosXtext.text),val(MousePosYtext.text))

MousePosOldX = val(MousePosXtext.text )   //update the Old position for future reference
MousePosOldY = val(MousePosYtext.text)

case 2
// Capture the current mouse position
ClearFocus
mouseXval.text = str(RemoteControlMBS.MacMousePositionX)
mouseYval.text = str(RemoteControlMBS.MacMousePositionY)
MousePosOldX = val(mouseXval.text )
MousePosOldY = val(mouseYval.text )

case 3
//Mouseclick
ClearFocus
dim x,y as integer
dim c as PresskeyMBS
c=new PresskeyMBS
p.mouseclick(true)
p.mouseclick(false)

case 4

case 5

case 6
//Move Mouse UP by mouse move value
ClearFocus
call RemoteControlMBS.MacMoveMouse(MousePosOldX - (val(MousePlusXtext.text)), MousePosOldY - val(MousePlusYtext.text))
MousePosOldX = (RemoteControlMBS.MacMousePositionX)
MousePosOldY = (RemoteControlMBS.MacMousePositionY)

case 7

case 8

case 9
//Move Mouse DOWN by mouse move value
ClearFocus
call RemoteControlMBS.MacMoveMouse(MousePosOldX + (val(MousePlusXtext.text)), MousePosOldY + val(MousePlusYtext.text))
MousePosOldX = (RemoteControlMBS.MacMousePositionX)
MousePosOldY = (RemoteControlMBS.MacMousePositionY)

case 11 'keypad minus

case 12 'keypad plus

End Select

p.mouseclick(false)
Serial1.Flush ( )
[/code]

This may be solved. I change the baud from 9600 to 57600 and added a CR to the single data byte coming in to the USB port and now I cannot get it to fail. Possibly if there were overlapping data before the DataReceived code completed, it was backing up.