mirror of https://github.com/quasar/Quasar.git
Improved Keyboard handling
This commit is contained in:
parent
efc44632a7
commit
f01b5550af
|
@ -101,7 +101,7 @@ public static void HandleDoMouseEvent(Packets.ServerPackets.DoMouseEvent command
|
|||
|
||||
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)
|
||||
|
|
|
@ -33,10 +33,9 @@ public static void DoMouseEventScroll(Point p, bool scrollDown)
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,17 @@ public class DoKeyboardEvent : IPacket
|
|||
[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)
|
||||
|
|
|
@ -9,13 +9,17 @@ public class DoKeyboardEvent : IPacket
|
|||
[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)
|
||||
|
|
|
@ -47,6 +47,7 @@ private void Subscribe(IKeyboardMouseEvents events)
|
|||
_mEvents = events;
|
||||
_mEvents.MouseWheel += MouseWheelEvent;
|
||||
_mEvents.KeyDown += OnKeyDown;
|
||||
_mEvents.KeyUp += OnKeyUp;
|
||||
}
|
||||
|
||||
private void Unsubscribe()
|
||||
|
@ -54,6 +55,7 @@ private void Unsubscribe()
|
|||
if (_mEvents == null) return;
|
||||
_mEvents.MouseWheel -= MouseWheelEvent;
|
||||
_mEvents.KeyDown -= OnKeyDown;
|
||||
_mEvents.KeyUp -= OnKeyUp;
|
||||
}
|
||||
|
||||
public void AddMonitors(int monitors)
|
||||
|
@ -210,7 +212,7 @@ private int GetRemoteHeight(int localY)
|
|||
|
||||
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 @@ private void picDesktop_MouseDown(object sender, MouseEventArgs e)
|
|||
|
||||
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 @@ private void picDesktop_MouseUp(object sender, MouseEventArgs e)
|
|||
|
||||
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 @@ private void picDesktop_MouseMove(object sender, MouseEventArgs e)
|
|||
|
||||
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 @@ private void OnKeyDown(object sender, KeyEventArgs e)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue