I have a C# WinForm application on .NET 2.0 an开发者_如何学Pythond XP. There is also an UltraVNC server running on the same PC as my application does. The user may access the application either locally at the PC or remotely via the UltraVNC server.
When some textboxes in the application receive a keystroke, the application would like to know if the keystroke is from the local keyboard or from the UltraVNC server. Is this possible? Also the same question for mouse clicks.
It won't disinguish the key-strokes, but you may be able to detect the RDP session via:
System.Windows.Forms.SystemInformation.TerminalServerSession
By setting a low level keyboard hook, you may check for the LLKHF_INJECTED flag in the event. If this flag is set, then the keystroke has been injected by other application (i.e. Teamviewer, VNC servers or other applications using SendInput() or the deprecated keybd_event()). Else, it probably came from a reliable source (the keyboard driver or a Microsoft Remote Desktop session). Please refer to MSDN to know more about this flag.
精彩评论