Skip to content

Commit

Permalink
Add 'findkeys' command
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed May 15, 2020
1 parent c938c35 commit b6105c4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
49 changes: 48 additions & 1 deletion GK6X/KeyboardDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ public void SetKeys(KeyboardLayer layer, uint[] values, bool fn)
}
}

public void SetIdentifyDriverMacros()
{
using (Packet packet = new Packet())
{
for (byte i = 0; i < byte.MaxValue; i++)
{
packet.WriteUInt32((uint)(0x0A010000 | i));
}
WritePacketNoResponse(OpCodes.DriverLayerSetKeyValues, (byte)OpCodes_SetDriverLayerKeyValues.KeySet, packet);
}
using (Packet packet = new Packet())
{
packet.WriteByte(1);
WritePacketNoResponse(OpCodes.DriverMacro, (byte)OpCodes_DriverMacro.BeginEnd, packet);
}
using (Packet packet = new Packet())
{
for (byte i = 0; i < byte.MaxValue; i++)
{
packet.WriteByte(i);
}
packet.WriteByte(0);
WritePacketNoResponse(OpCodes.DriverMacro, (byte)OpCodes_DriverMacro.KeyboardState, packet);
}
using (Packet packet = new Packet())
{
packet.WriteByte(0);
WritePacketNoResponse(OpCodes.DriverMacro, (byte)OpCodes_DriverMacro.BeginEnd, packet);
}
}

public void WritePacketNoResponse(OpCodes op1, byte op2, Packet packet, byte op3 = 0)
{
using (Packet response = new Packet())
Expand All @@ -345,9 +376,9 @@ public Packet WritePacket(OpCodes op1, byte op2, Packet packet, byte op3 = 0)
int lengthOffset = 4;
switch (op1)
{
case OpCodes.DriverLayerSetKeyValues:
case OpCodes.DriverLayerUpdateRealtimeLighting:
case OpCodes.LayerSetLightValues:
case OpCodes.DriverLayerSetKeyValues:
offsetOffset = 2;
lengthOffset = 5;
allowsLongOffset = true;
Expand Down Expand Up @@ -446,6 +477,22 @@ private byte[] GetResponse(byte op1, byte op2)
Buffer.BlockCopy(resultBufferWithReportId, 1, resultBuffer, 0, resultBuffer.Length);
return resultBuffer;
}
else if (resultBufferWithReportId[1] == (byte)OpCodes.DriverKeyCallback)
{
byte callbackId = resultBufferWithReportId[3];
bool callbackKeyDown = resultBufferWithReportId[4] != 0;
if (callbackKeyDown)
{
KeyboardState.Key key;
State.KeysByLogicCode.TryGetValue(callbackId, out key);
Program.Log("index:" + callbackId + " key " +
(key == null ? "(null)" :
"name: " + key.KeyName + " " +
"logicCode: " + key.LogicCode + " " +
"locationCode: " + key.LocationCode + " " +
"driverValue: " + key.DriverValue));
}
}
else if (!Crc16.ValidateCrc(resultBufferWithReportId, reportHeaderLen, reportHeaderLen + 6))
{
return null;
Expand Down
35 changes: 35 additions & 0 deletions GK6X/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,41 @@ static void Main(string[] args)
case "gui":
WebGUI.Run();
break;
case "findkeys":
{
Log(string.Empty);
Log("This is used to identify keys. Press keys to see their values. Missing keys will generally show up as '(null)' and they need to be mapped in the data files Data/devuces/YOUR_MODEL_ID/");
Log(string.Empty);
Log("This will enter the 'driver' layer and map all keys to callbacks. This results in modifer keys becoming stuck (LCtrl, RAlt, RShift, etc). While it may be " +
"possible to de-press some of these keys manually, some may become stuck and require a system reboot to clear. It might be best to run this inside a VM. " +
"Do you want to continue? (y/n)");
Log(string.Empty);
string confirm = Console.ReadLine();
if (!string.IsNullOrEmpty(confirm))
{
switch (confirm.ToLower())
{
case "y":
case "ye":
case "yes":
Log("Entering driver mode...");
KeyboardDevice[] devices;
if (TryGetDevices(out devices))
{
foreach (KeyboardDevice device in devices)
{
device.SetLayer(KeyboardLayer.Driver);
device.SetIdentifyDriverMacros();
}
}
break;
default:
Log("Cancelled");
break;
}
}
}
break;
case "map":
case "unmap":
{
Expand Down

0 comments on commit b6105c4

Please sign in to comment.