1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-15 15:53:45 +00:00

Added unicode key support.

This commit is contained in:
Ylian Saint-Hilaire
2020-11-20 07:25:41 -08:00
parent 2b6bfdae4c
commit a8e9615e37
5 changed files with 107 additions and 20 deletions

View File

@@ -38,6 +38,7 @@ namespace MeshCentralRouter
private int scalinglevel = 1024; // 100% scale private int scalinglevel = 1024; // 100% scale
private int frameRate = 100; // Medium frame rate private int frameRate = 100; // Medium frame rate
private bool swamMouseButtons = false; private bool swamMouseButtons = false;
private bool remoteKeybaordMap = false;
private double scalefactor = 1; private double scalefactor = 1;
public List<string> displays = new List<string>(); public List<string> displays = new List<string>();
public ushort currentDisp = 0; public ushort currentDisp = 0;
@@ -49,6 +50,7 @@ namespace MeshCentralRouter
public KVMViewer parent = null; public KVMViewer parent = null;
private readonly KVMControlHook.KVMCallback KeyboardCallback; private readonly KVMControlHook.KVMCallback KeyboardCallback;
private bool keyboardIsAttached; private bool keyboardIsAttached;
private long killNextKeyPress = 0;
private enum KvmCommands private enum KvmCommands
@@ -73,6 +75,7 @@ namespace MeshCentralRouter
Jumbo = 27, Jumbo = 27,
Disconnect = 59, Disconnect = 59,
Alert = 65, Alert = 65,
KeyUnicode = 85,
MouseCursor = 88 MouseCursor = 88
} }
@@ -105,6 +108,7 @@ namespace MeshCentralRouter
public int ScalingLevel { get { return scalinglevel; } set { scalinglevel = value; SendCompressionLevel(); } } public int ScalingLevel { get { return scalinglevel; } set { scalinglevel = value; SendCompressionLevel(); } }
public int FrameRate { get { return frameRate; } set { frameRate = value; SendCompressionLevel(); } } public int FrameRate { get { return frameRate; } set { frameRate = value; SendCompressionLevel(); } }
public bool SwamMouseButtons { get { return swamMouseButtons; } set { swamMouseButtons = value; } } public bool SwamMouseButtons { get { return swamMouseButtons; } set { swamMouseButtons = value; } }
public bool RemoteKeybaordMap { get { return remoteKeybaordMap; } set { remoteKeybaordMap = value; } }
public double ScaleFactor { get { return scalefactor; } set { scalefactor = value; } } public double ScaleFactor { get { return scalefactor; } set { scalefactor = value; } }
@@ -374,18 +378,53 @@ namespace MeshCentralRouter
Send(bw); Send(bw);
} }
private void SendKey(KeyEventArgs e, byte action) public void SendUnicodeKey(ushort key, byte action)
{ {
//if (state != ConnectState.Connected) return; //if (state != ConnectState.Connected) return;
BinaryWriter bw = GetBinaryWriter(); BinaryWriter bw = GetBinaryWriter();
bw.Write(IPAddress.HostToNetworkOrder((short)KvmCommands.Key)); bw.Write(IPAddress.HostToNetworkOrder((short)KvmCommands.KeyUnicode));
bw.Write(IPAddress.HostToNetworkOrder((short)6)); bw.Write(IPAddress.HostToNetworkOrder((short)7));
bw.Write((byte)action); bw.Write((byte)action);
bw.Write((byte)e.KeyCode); bw.Write((byte)(key >> 8));
bw.Write((byte)(key & 0xFF));
Send(bw); Send(bw);
} }
private void SendPress(KeyPressEventArgs e, byte action)
{
//if (state != ConnectState.Connected) return;
if (remoteKeybaordMap == true) return;
if (killNextKeyPress > 0) {
long t = DateTime.Now.Ticks;
if ((t - killNextKeyPress) < 10) { killNextKeyPress = 0; return; }
}
ushort c = (ushort)e.KeyChar;
if (c < 32)
{
SendKey((byte)c, 0);
}
else
{
SendUnicodeKey(c, 0);
}
}
private void SendKey(KeyEventArgs e, byte action)
{
//if (state != ConnectState.Connected) return;
if (remoteKeybaordMap == true) { SendKey((byte)e.KeyCode, action); return; } // Use old key system that uses the remote keyboard mapping.
string keycode = e.KeyCode.ToString();
if ((action == 0) && (e.Control == false) && (e.Alt == false) && (((e.KeyValue >= 48) && (e.KeyValue <= 57)) || (keycode.Length == 1) || (keycode.StartsWith("Oem") == true))) return;
if ((e.Control == true) || (e.Alt == true)) { killNextKeyPress = DateTime.Now.Ticks; }
SendKey((byte)e.KeyCode, action);
e.Handled = true;
}
private short LastX = 0; private short LastX = 0;
private short LastY = 0; private short LastY = 0;
private void SendMouse(MouseEventArgs e, byte action) private void SendMouse(MouseEventArgs e, byte action)
@@ -655,6 +694,7 @@ namespace MeshCentralRouter
private void KVMControl_KeyPress(object sender, KeyPressEventArgs e) private void KVMControl_KeyPress(object sender, KeyPressEventArgs e)
{ {
SendPress(e, 0);
e.Handled = true; e.Handled = true;
} }

View File

@@ -32,6 +32,7 @@
this.cancelButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button(); this.okButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox();
this.frameRateComboBox = new System.Windows.Forms.ComboBox(); this.frameRateComboBox = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.scalingComboBox = new System.Windows.Forms.ComboBox(); this.scalingComboBox = new System.Windows.Forms.ComboBox();
@@ -40,7 +41,7 @@
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox(); this.remoteKeyboardMapCheckBox = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@@ -63,6 +64,7 @@
// groupBox1 // groupBox1
// //
resources.ApplyResources(this.groupBox1, "groupBox1"); resources.ApplyResources(this.groupBox1, "groupBox1");
this.groupBox1.Controls.Add(this.remoteKeyboardMapCheckBox);
this.groupBox1.Controls.Add(this.swapMouseButtonsCheckBox); this.groupBox1.Controls.Add(this.swapMouseButtonsCheckBox);
this.groupBox1.Controls.Add(this.frameRateComboBox); this.groupBox1.Controls.Add(this.frameRateComboBox);
this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label2);
@@ -73,6 +75,12 @@
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
// //
// swapMouseButtonsCheckBox
//
resources.ApplyResources(this.swapMouseButtonsCheckBox, "swapMouseButtonsCheckBox");
this.swapMouseButtonsCheckBox.Name = "swapMouseButtonsCheckBox";
this.swapMouseButtonsCheckBox.UseVisualStyleBackColor = true;
//
// frameRateComboBox // frameRateComboBox
// //
resources.ApplyResources(this.frameRateComboBox, "frameRateComboBox"); resources.ApplyResources(this.frameRateComboBox, "frameRateComboBox");
@@ -121,11 +129,11 @@
resources.ApplyResources(this.label4, "label4"); resources.ApplyResources(this.label4, "label4");
this.label4.Name = "label4"; this.label4.Name = "label4";
// //
// swapMouseButtonsCheckBox // remoteKeyboardMapCheckBox
// //
resources.ApplyResources(this.swapMouseButtonsCheckBox, "swapMouseButtonsCheckBox"); resources.ApplyResources(this.remoteKeyboardMapCheckBox, "remoteKeyboardMapCheckBox");
this.swapMouseButtonsCheckBox.Name = "swapMouseButtonsCheckBox"; this.remoteKeyboardMapCheckBox.Name = "remoteKeyboardMapCheckBox";
this.swapMouseButtonsCheckBox.UseVisualStyleBackColor = true; this.remoteKeyboardMapCheckBox.UseVisualStyleBackColor = true;
// //
// KVMSettingsForm // KVMSettingsForm
// //
@@ -164,5 +172,6 @@
private System.Windows.Forms.ComboBox qualityComboBox; private System.Windows.Forms.ComboBox qualityComboBox;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox swapMouseButtonsCheckBox; private System.Windows.Forms.CheckBox swapMouseButtonsCheckBox;
private System.Windows.Forms.CheckBox remoteKeyboardMapCheckBox;
} }
} }

View File

@@ -124,6 +124,12 @@ namespace MeshCentralRouter
set { swapMouseButtonsCheckBox.Checked = value; } set { swapMouseButtonsCheckBox.Checked = value; }
} }
public bool RemoteKeybaordMap
{
get { return remoteKeyboardMapCheckBox.Checked; }
set { remoteKeyboardMapCheckBox.Checked = value; }
}
private void okButton_Click(object sender, EventArgs e) private void okButton_Click(object sender, EventArgs e)
{ {
DialogResult = System.Windows.Forms.DialogResult.OK; DialogResult = System.Windows.Forms.DialogResult.OK;

View File

@@ -123,7 +123,7 @@
</data> </data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="cancelButton.Location" type="System.Drawing.Point, System.Drawing"> <data name="cancelButton.Location" type="System.Drawing.Point, System.Drawing">
<value>312, 207</value> <value>312, 236</value>
</data> </data>
<data name="cancelButton.Size" type="System.Drawing.Size, System.Drawing"> <data name="cancelButton.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value> <value>75, 23</value>
@@ -151,7 +151,7 @@
<value>Bottom, Right</value> <value>Bottom, Right</value>
</data> </data>
<data name="okButton.Location" type="System.Drawing.Point, System.Drawing"> <data name="okButton.Location" type="System.Drawing.Point, System.Drawing">
<value>231, 207</value> <value>231, 236</value>
</data> </data>
<data name="okButton.Size" type="System.Drawing.Size, System.Drawing"> <data name="okButton.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value> <value>75, 23</value>
@@ -177,6 +177,36 @@
<data name="groupBox1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="groupBox1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value> <value>Top, Bottom, Left, Right</value>
</data> </data>
<data name="remoteKeyboardMapCheckBox.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="remoteKeyboardMapCheckBox.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="remoteKeyboardMapCheckBox.Location" type="System.Drawing.Point, System.Drawing">
<value>128, 128</value>
</data>
<data name="remoteKeyboardMapCheckBox.Size" type="System.Drawing.Size, System.Drawing">
<value>157, 17</value>
</data>
<data name="remoteKeyboardMapCheckBox.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
</data>
<data name="remoteKeyboardMapCheckBox.Text" xml:space="preserve">
<value>Use Remote Keyboard Map</value>
</data>
<data name="&gt;&gt;remoteKeyboardMapCheckBox.Name" xml:space="preserve">
<value>remoteKeyboardMapCheckBox</value>
</data>
<data name="&gt;&gt;remoteKeyboardMapCheckBox.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;remoteKeyboardMapCheckBox.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;remoteKeyboardMapCheckBox.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="swapMouseButtonsCheckBox.AutoSize" type="System.Boolean, mscorlib"> <data name="swapMouseButtonsCheckBox.AutoSize" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
</data> </data>
@@ -202,7 +232,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;swapMouseButtonsCheckBox.ZOrder" xml:space="preserve"> <data name="&gt;&gt;swapMouseButtonsCheckBox.ZOrder" xml:space="preserve">
<value>0</value> <value>1</value>
</data> </data>
<data name="frameRateComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="frameRateComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value> <value>Top, Left, Right</value>
@@ -226,7 +256,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;frameRateComboBox.ZOrder" xml:space="preserve"> <data name="&gt;&gt;frameRateComboBox.ZOrder" xml:space="preserve">
<value>1</value> <value>2</value>
</data> </data>
<data name="label2.AutoSize" type="System.Boolean, mscorlib"> <data name="label2.AutoSize" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
@@ -253,7 +283,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve"> <data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>2</value> <value>3</value>
</data> </data>
<data name="scalingComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="scalingComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value> <value>Top, Left, Right</value>
@@ -277,7 +307,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;scalingComboBox.ZOrder" xml:space="preserve"> <data name="&gt;&gt;scalingComboBox.ZOrder" xml:space="preserve">
<value>3</value> <value>4</value>
</data> </data>
<data name="label1.AutoSize" type="System.Boolean, mscorlib"> <data name="label1.AutoSize" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
@@ -304,7 +334,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve"> <data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>4</value> <value>5</value>
</data> </data>
<data name="qualityComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="qualityComboBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value> <value>Top, Left, Right</value>
@@ -328,7 +358,7 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;qualityComboBox.ZOrder" xml:space="preserve"> <data name="&gt;&gt;qualityComboBox.ZOrder" xml:space="preserve">
<value>5</value> <value>6</value>
</data> </data>
<data name="label3.AutoSize" type="System.Boolean, mscorlib"> <data name="label3.AutoSize" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
@@ -355,13 +385,13 @@
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;label3.ZOrder" xml:space="preserve"> <data name="&gt;&gt;label3.ZOrder" xml:space="preserve">
<value>6</value> <value>7</value>
</data> </data>
<data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing"> <data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 68</value> <value>12, 68</value>
</data> </data>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing"> <data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>375, 133</value> <value>375, 162</value>
</data> </data>
<data name="groupBox1.TabIndex" type="System.Int32, mscorlib"> <data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
<value>2</value> <value>2</value>
@@ -439,7 +469,7 @@
<value>6, 13</value> <value>6, 13</value>
</data> </data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>399, 242</value> <value>399, 271</value>
</data> </data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>

View File

@@ -344,10 +344,12 @@ namespace MeshCentralRouter
form.Scaling = kvmControl.ScalingLevel; form.Scaling = kvmControl.ScalingLevel;
form.FrameRate = kvmControl.FrameRate; form.FrameRate = kvmControl.FrameRate;
form.SwamMouseButtons = kvmControl.SwamMouseButtons; form.SwamMouseButtons = kvmControl.SwamMouseButtons;
form.RemoteKeybaordMap = kvmControl.RemoteKeybaordMap;
if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{ {
kvmControl.SetCompressionParams(form.Compression, form.Scaling, form.FrameRate); kvmControl.SetCompressionParams(form.Compression, form.Scaling, form.FrameRate);
kvmControl.SwamMouseButtons = form.SwamMouseButtons; kvmControl.SwamMouseButtons = form.SwamMouseButtons;
kvmControl.RemoteKeybaordMap = form.RemoteKeybaordMap;
} }
} }
} }