Improved Keyboard handling

This commit is contained in:
d3agle 2015-07-29 09:21:49 -05:00
parent efc44632a7
commit f01b5550af
5 changed files with 29 additions and 11 deletions

View File

@ -101,7 +101,7 @@ namespace xClient.Core.Commands
public static void HandleDoKeyboardEvent(Packets.ServerPackets.DoKeyboardEvent command, Client client)
{
NativeMethodsHelper.DoKeyPress(command.Key);
NativeMethodsHelper.DoKeyPress(command.Key, command.KeyDown);
}
public static void HandleGetMonitors(Packets.ServerPackets.GetMonitors command, Client client)

View File

@ -33,10 +33,9 @@ namespace xClient.Core.Helper
NativeMethods.mouse_event(MOUSEEVENTF_WHEEL, p.X, p.Y, scrollDown ? -120 : 120, 0);
}
public static void DoKeyPress(byte key)
public static void DoKeyPress(byte key, bool keyDown)
{
NativeMethods.keybd_event(key, 0, KEYEVENTF_KEYDOWN, 0);
NativeMethods.keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
NativeMethods.keybd_event(key, 0, keyDown ? KEYEVENTF_KEYDOWN : KEYEVENTF_KEYUP, 0);
}
}
}

View File

@ -9,13 +9,17 @@ namespace xClient.Core.Packets.ServerPackets
[ProtoMember(1)]
public byte Key { get; set; }
[ProtoMember(2)]
public bool KeyDown { get; set; }
public DoKeyboardEvent()
{
}
public DoKeyboardEvent(byte key)
public DoKeyboardEvent(byte key, bool keyDown)
{
this.Key = key;
this.KeyDown = keyDown;
}
public void Execute(Client client)

View File

@ -9,13 +9,17 @@ namespace xServer.Core.Packets.ServerPackets
[ProtoMember(1)]
public byte Key { get; set; }
[ProtoMember(2)]
public bool KeyDown { get; set; }
public DoKeyboardEvent()
{
}
public DoKeyboardEvent(byte key)
public DoKeyboardEvent(byte key, bool keyDown)
{
this.Key = key;
this.KeyDown = keyDown;
}
public void Execute(Client client)

View File

@ -47,6 +47,7 @@ namespace xServer.Forms
_mEvents = events;
_mEvents.MouseWheel += MouseWheelEvent;
_mEvents.KeyDown += OnKeyDown;
_mEvents.KeyUp += OnKeyUp;
}
private void Unsubscribe()
@ -54,6 +55,7 @@ namespace xServer.Forms
if (_mEvents == null) return;
_mEvents.MouseWheel -= MouseWheelEvent;
_mEvents.KeyDown -= OnKeyDown;
_mEvents.KeyUp -= OnKeyUp;
}
public void AddMonitors(int monitors)
@ -210,7 +212,7 @@ namespace xServer.Forms
private void picDesktop_MouseDown(object sender, MouseEventArgs e)
{
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled)
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled && this.ContainsFocus)
{
int local_x = e.X;
int local_y = e.Y;
@ -234,7 +236,7 @@ namespace xServer.Forms
private void picDesktop_MouseUp(object sender, MouseEventArgs e)
{
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled)
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled && this.ContainsFocus)
{
int local_x = e.X;
int local_y = e.Y;
@ -258,7 +260,7 @@ namespace xServer.Forms
private void picDesktop_MouseMove(object sender, MouseEventArgs e)
{
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled)
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled && this.ContainsFocus)
{
int local_x = e.X;
int local_y = e.Y;
@ -275,7 +277,7 @@ namespace xServer.Forms
private void MouseWheelEvent(object sender, MouseEventArgs e)
{
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled)
if (picDesktop.Image != null && _enableMouseInput && !btnStart.Enabled && this.ContainsFocus)
{
if (_connectClient != null)
new Core.Packets.ServerPackets.DoMouseEvent(e.Delta == 120 ? MouseAction.ScrollUp : MouseAction.ScrollDown, false, 0, 0, cbMonitors.SelectedIndex).Execute(_connectClient);
@ -287,7 +289,16 @@ namespace xServer.Forms
if (picDesktop.Image != null && !btnStart.Enabled && this.ContainsFocus)
{
if (_connectClient != null)
new Core.Packets.ServerPackets.DoKeyboardEvent((byte)e.KeyCode).Execute(_connectClient);
new Core.Packets.ServerPackets.DoKeyboardEvent((byte)e.KeyCode, true).Execute(_connectClient);
}
}
private void OnKeyUp(object sender, KeyEventArgs e)
{
if (picDesktop.Image != null && !btnStart.Enabled && this.ContainsFocus)
{
if (_connectClient != null)
new Core.Packets.ServerPackets.DoKeyboardEvent((byte)e.KeyCode, false).Execute(_connectClient);
}
}