Skip to content

Commit

Permalink
AltGr and typing indicator should work now
Browse files Browse the repository at this point in the history
i swear if thw woekflow fails
  • Loading branch information
nyakowint committed Sep 21, 2023
1 parent 1be96af commit f753f3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
28 changes: 11 additions & 17 deletions KeyboardOSC/ChatModeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ChatModeManager
private static bool _isSilentMsg;
private static string _currentText = "";
private static string _lastMsg = "";
private static DateTime _lastPingTime;
private static DateTime _lastTypingTime;
private static readonly ManualLogSource Logger = Plugin.PluginLogger;
private static TextMeshProUGUI _oscBarText;
private static List<KeyboardKey> _currentlyDownStickyKeys = new();
Expand All @@ -28,11 +28,13 @@ public static void HandleKey(KeyboardKey.VirtualKeyEventData eventData)
? (uint) eventData.KeyCode[0]
: eventData.Sender.ScanCode[0];
var shiftedField = AccessTools.Field(typeof(KeyboardKey), "IsShifted");
var altedField = AccessTools.Field(typeof(KeyboardKey), "IsAlted");
var isShifted = (bool) shiftedField.GetValue(eventData.Sender);
var isAlted = (bool) altedField.GetValue(eventData.Sender); // altGr

foreach (var key in eventData.KeyCode)
{
var character = Tools.ConvertVirtualKeyToUnicode(key, scanCode, isShifted);
var character = Tools.ConvertVirtualKeyToUnicode(key, scanCode, isShifted, isAlted);
ProcessKey(key, eventData, character);
}
}
Expand Down Expand Up @@ -93,7 +95,6 @@ private static void ProcessKey(VirtualKeyCode key, KeyboardKey.VirtualKeyEventDa
}


// send to vrchat
if (key is VirtualKeyCode.RETURN)
{
if (_currentText.Length <= 0) return;
Expand All @@ -110,29 +111,22 @@ private static void ProcessKey(VirtualKeyCode key, KeyboardKey.VirtualKeyEventDa
}


if (string.IsNullOrEmpty(character)) return;
SendTyping(true);
_currentText += character;
UpdateChatText(_currentText);
SendTyping(true);
Logger.LogInfo("updating chat text with " + _currentText);
}

public static void SendTyping(bool typing)
private static void SendMessage(string address, string msg, bool now, bool sound)
{
if (DateTime.Now - _lastPingTime < TimeSpan.FromSeconds(2) && typing) return;
_lastPingTime = DateTime.Now;
if (typing)
{
Tools.SendOsc("/chatbox/typing", "true");
return;
}

Tools.SendOsc("/chatbox/typing", "false");
Tools.SendOsc(address, msg, now, sound);
}

private static void SendMessage(string address, string msg, bool now, bool sound)
private static void SendTyping(bool typing)
{
Tools.SendOsc(address, msg, now, sound);
if (typing && (DateTime.Now - _lastTypingTime).TotalSeconds <= 2) return;
_lastTypingTime = DateTime.Now;
Tools.SendOsc("/chatbox/typing", typing);
}

public static void Setup(TextMeshProUGUI obText)
Expand Down
2 changes: 1 addition & 1 deletion KeyboardOSC/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private void Start()

ServerBridge.Instance.CommandMap["Keyboard"] = delegate
{
Overlay_Manager.Instance.EnableKeyboard();
InitializeKeyboard();
Overlay_Manager.Instance.EnableKeyboard();
};
}

Expand Down
17 changes: 14 additions & 3 deletions KeyboardOSC/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,27 @@ public static void SendBread(string title, string content)
content = content,
messageType = 1,
timeout = 5f,
sourceApp = "Keyboard Plugin",
height = calculateHeight(content),
sourceApp = "KeyboardOSC Plugin",
volume = 0.5f
};
NotificationHandler.Instance.PrepareToast(notif);
}


public static string ConvertVirtualKeyToUnicode(VirtualKeyCode keyCode, uint scanCode, bool shift)
public static string ConvertVirtualKeyToUnicode(VirtualKeyCode keyCode, uint scanCode, bool shift, bool altGr)
{
return GetCharsFromKeys(keyCode, scanCode, shift, false);
return GetCharsFromKeys(keyCode, scanCode, shift, altGr);
}

private static int calculateHeight(string content) {
return content.Length switch
{
<= 100 => 100,
<= 200 => 150,
<= 300 => 200,
_ => 250
};
}

public static void DestroyComponent<T>(this GameObject go) where T : Component
Expand Down

0 comments on commit f753f3e

Please sign in to comment.