RDP Mono keyboard input

Changed controls with tabstop to false to prevent tab presses
This commit is contained in:
d3agle 2015-07-30 09:07:04 -05:00
parent f871710d2e
commit 9a514be262
2 changed files with 58 additions and 5 deletions

View File

@ -54,6 +54,7 @@ private void InitializeComponent()
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(68, 23);
this.btnStart.TabIndex = 1;
this.btnStart.TabStop = false;
this.btnStart.Text = "Start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
@ -65,6 +66,7 @@ private void InitializeComponent()
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(68, 23);
this.btnStop.TabIndex = 2;
this.btnStop.TabStop = false;
this.btnStop.Text = "Stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
@ -77,6 +79,7 @@ private void InitializeComponent()
this.barQuality.Name = "barQuality";
this.barQuality.Size = new System.Drawing.Size(76, 45);
this.barQuality.TabIndex = 3;
this.barQuality.TabStop = false;
this.barQuality.Value = 75;
this.barQuality.Scroll += new System.EventHandler(this.barQuality_Scroll);
//
@ -105,6 +108,7 @@ private void InitializeComponent()
this.btnMouse.Name = "btnMouse";
this.btnMouse.Size = new System.Drawing.Size(28, 28);
this.btnMouse.TabIndex = 6;
this.btnMouse.TabStop = false;
this.toolTipButtons.SetToolTip(this.btnMouse, "Enable mouse input.");
this.btnMouse.UseVisualStyleBackColor = true;
this.btnMouse.Click += new System.EventHandler(this.btnMouse_Click);
@ -133,6 +137,7 @@ private void InitializeComponent()
this.btnKeyboard.Name = "btnKeyboard";
this.btnKeyboard.Size = new System.Drawing.Size(28, 28);
this.btnKeyboard.TabIndex = 9;
this.btnKeyboard.TabStop = false;
this.toolTipButtons.SetToolTip(this.btnKeyboard, "Enable keyboard input.");
this.btnKeyboard.UseVisualStyleBackColor = true;
this.btnKeyboard.Click += new System.EventHandler(this.btnKeyboard_Click);
@ -145,6 +150,7 @@ private void InitializeComponent()
this.cbMonitors.Name = "cbMonitors";
this.cbMonitors.Size = new System.Drawing.Size(149, 21);
this.cbMonitors.TabIndex = 8;
this.cbMonitors.TabStop = false;
//
// btnHide
//
@ -152,6 +158,7 @@ private void InitializeComponent()
this.btnHide.Name = "btnHide";
this.btnHide.Size = new System.Drawing.Size(54, 19);
this.btnHide.TabIndex = 7;
this.btnHide.TabStop = false;
this.btnHide.Text = "Hide";
this.btnHide.UseVisualStyleBackColor = true;
this.btnHide.Click += new System.EventHandler(this.btnHide_Click);
@ -162,6 +169,7 @@ private void InitializeComponent()
this.btnShow.Name = "btnShow";
this.btnShow.Size = new System.Drawing.Size(54, 19);
this.btnShow.TabIndex = 8;
this.btnShow.TabStop = false;
this.btnShow.Text = "Show";
this.btnShow.UseVisualStyleBackColor = true;
this.btnShow.Visible = false;

View File

@ -26,7 +26,9 @@ public FrmRemoteDesktop(Client c)
_connectClient.Value.FrmRdp = this;
if (!PlatformHelper.RunningOnMono)
Subscribe(Hook.GlobalEvents());
SubscribeWindowsHookEvents(Hook.GlobalEvents());
else
SubscribeMonoEvents();
InitializeComponent();
}
@ -42,14 +44,13 @@ private void FrmRemoteDesktop_Load(object sender, EventArgs e)
btnShow.Location = new Point(377, 0);
btnShow.Left = (this.Width / 2) - (btnShow.Width / 2);
_enableKeyboardInput = false;
_keysPressed = new List<Keys>();
if (_connectClient.Value != null)
new Core.Packets.ServerPackets.GetMonitors().Execute(_connectClient);
}
private void Subscribe(IKeyboardMouseEvents events)
private void SubscribeWindowsHookEvents(IKeyboardMouseEvents events)
{
_mEvents = events;
_mEvents.MouseWheel += MouseWheelEvent;
@ -57,7 +58,13 @@ private void Subscribe(IKeyboardMouseEvents events)
_mEvents.KeyUp += OnKeyUp;
}
private void Unsubscribe()
private void SubscribeMonoEvents()
{
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FrmRemoteDesktop_KeyDown);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.FrmRemoteDesktop_KeyUp);
}
private void UnsubscribeWindowsHookEvents()
{
if (_mEvents == null) return;
_mEvents.MouseWheel -= MouseWheelEvent;
@ -65,6 +72,12 @@ private void Unsubscribe()
_mEvents.KeyUp -= OnKeyUp;
}
private void UnsubscribeMonoEvents()
{
this.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.FrmRemoteDesktop_KeyDown);
this.KeyUp -= new System.Windows.Forms.KeyEventHandler(this.FrmRemoteDesktop_KeyUp);
}
public void AddMonitors(int monitors)
{
try
@ -124,7 +137,10 @@ private void FrmRemoteDesktop_FormClosing(object sender, FormClosingEventArgs e)
if (_connectClient.Value != null)
_connectClient.Value.FrmRdp = null;
Unsubscribe();
if (!PlatformHelper.RunningOnMono)
UnsubscribeWindowsHookEvents();
else
UnsubscribeMonoEvents();
}
private void FrmRemoteDesktop_Resize(object sender, EventArgs e)
@ -334,6 +350,35 @@ private void OnKeyUp(object sender, KeyEventArgs e)
}
}
private void FrmRemoteDesktop_KeyDown(object sender, KeyEventArgs e)
{
if (picDesktop.Image != null && _enableKeyboardInput && IsStarted && this.ContainsFocus)
{
e.Handled = true;
if (_keysPressed.Contains(e.KeyCode))
return;
_keysPressed.Add(e.KeyCode);
if (_connectClient != null)
new Core.Packets.ServerPackets.DoKeyboardEvent((byte)e.KeyCode, true).Execute(_connectClient);
}
}
private void FrmRemoteDesktop_KeyUp(object sender, KeyEventArgs e)
{
if (picDesktop.Image != null && _enableKeyboardInput && IsStarted && this.ContainsFocus)
{
e.Handled = true;
_keysPressed.Remove(e.KeyCode);
if (_connectClient != null)
new Core.Packets.ServerPackets.DoKeyboardEvent((byte)e.KeyCode, false).Execute(_connectClient);
}
}
private void btnHide_Click(object sender, EventArgs e)
{
panelTop.Visible = false;