From 9d0b741e7b1ced233cd791f51e1c975b60d43acd Mon Sep 17 00:00:00 2001 From: EverythingWindows Date: Thu, 17 Nov 2022 11:44:01 +0700 Subject: [PATCH] Added KeyboardHandler to handle shortcuts and key input to make it universally used --- .../InGame/Hardwares/KeyboardHandler.vb | 51 +++++++++++++++++++ ShiftOS-TheRevival/MainForms/Console.vb | 12 +---- ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj | 1 + .../External/TerminalExternalApps.vb | 31 ----------- 4 files changed, 54 insertions(+), 41 deletions(-) create mode 100644 ShiftOS-TheRevival/Functions/InGame/Hardwares/KeyboardHandler.vb diff --git a/ShiftOS-TheRevival/Functions/InGame/Hardwares/KeyboardHandler.vb b/ShiftOS-TheRevival/Functions/InGame/Hardwares/KeyboardHandler.vb new file mode 100644 index 0000000..26aca44 --- /dev/null +++ b/ShiftOS-TheRevival/Functions/InGame/Hardwares/KeyboardHandler.vb @@ -0,0 +1,51 @@ +Imports System.IO + +Module KeyboardHandler + Public InputKey As Keys + + Public Sub ShortcutHandle() + Select Case InputKey + Case (Keys.Control + Keys.Q) + If Console.CurrentInterpreter = "terminal" Then + Else + TerminateApp(KeyInput) + TextRebind() + End If + Case Else + ExecKeyBinding(KeyInput) + End Select + End Sub + + Public Sub ExecKeyBinding(KeyInput As Keys) + Select Case KeyInput + Case (Keys.S + Keys.Control) + Select Case Console.CurrentInterpreter + Case "textpad" + If File.Exists(Console.CurrentDirectory & "\" & command) = True Then + Dim TempCompare As String = File.ReadAllText(Console.CurrentDirectory & "\" & command) + If Console.TextBox1.Text = TempCompare Then + + Else + Dim BeforeCP As Integer = Strings.ComputerInfo(2) + SaveFile(command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Console.ToolBar.Text = "TextPad - " & command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" + End If + Else + Dim BeforeCP As Integer = Strings.ComputerInfo(2) + SaveFile(command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Console.ToolBar.Text = "TextPad - " & command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" + End If + End Select + Case (Keys.N + Keys.Control) + Select Case Console.CurrentInterpreter + Case "textpad" + Console.TextBox1.Text = Nothing + End Select + End Select + End Sub + +End Module diff --git a/ShiftOS-TheRevival/MainForms/Console.vb b/ShiftOS-TheRevival/MainForms/Console.vb index 5e8ef82..5dca6dc 100644 --- a/ShiftOS-TheRevival/MainForms/Console.vb +++ b/ShiftOS-TheRevival/MainForms/Console.vb @@ -98,16 +98,8 @@ Public Class Console Private Sub txtterm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown KeyInput = e.KeyData - Select Case e.KeyData - Case (Keys.Control + Keys.Q) - If CurrentInterpreter = "terminal" Then - Else - TerminateApp(KeyInput) - TextRebind() - End If - Case Else - CaptureKeyBinding(KeyInput) - End Select + InputKey = e.KeyData + ShortcutHandle() If ReleaseCursor = True Then Else diff --git a/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj b/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj index 065208b..8a84f82 100644 --- a/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj +++ b/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj @@ -93,6 +93,7 @@ + diff --git a/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb b/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb index 3f91782..b3ef9d5 100644 --- a/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb +++ b/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb @@ -73,37 +73,6 @@ Module TerminalExternalApps End If End Sub - Public Sub CaptureKeyBinding(KeysInput As Keys) - Select Case KeysInput - Case (Keys.S + Keys.Control) - Select Case Console.CurrentInterpreter - Case "textpad" - If File.Exists(Console.CurrentDirectory & "\" & command) = True Then - Dim TempCompare As String = File.ReadAllText(Console.CurrentDirectory & "\" & command) - If Console.TextBox1.Text = TempCompare Then - - Else - Dim BeforeCP As Integer = Strings.ComputerInfo(2) - SaveFile(command) - TextPad_GenerateCP_SavedFile() - Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP - Console.ToolBar.Text = "TextPad - " & command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" - End If - Else - Dim BeforeCP As Integer = Strings.ComputerInfo(2) - SaveFile(command) - TextPad_GenerateCP_SavedFile() - Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP - Console.ToolBar.Text = "TextPad - " & command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" - End If - End Select - Case (Keys.N + Keys.Control) - Select Case Console.CurrentInterpreter - Case "textpad" - Console.TextBox1.Text = Nothing - End Select - End Select - End Sub Public Sub TerminateApp(KeyInput As Keys) Select Case Console.CurrentInterpreter