From 2d9e582854ab0594fe70334021ff26f90541fd10 Mon Sep 17 00:00:00 2001 From: moosecrab Date: Tue, 16 Jun 2020 01:32:53 -0700 Subject: [PATCH] Changed path AJAX requests to query strings, among other things. --- webmouse/input.vb | 206 +++++++++++++++++++++++++++++++++++--- webmouse/main.Designer.vb | 5 +- webmouse/main.vb | 163 +++++++++++++++++++++--------- webmouse/webmouse.vbproj | 5 +- 4 files changed, 313 insertions(+), 66 deletions(-) diff --git a/webmouse/input.vb b/webmouse/input.vb index d7a8823..0157a8f 100755 --- a/webmouse/input.vb +++ b/webmouse/input.vb @@ -2,7 +2,7 @@ Module input - +#Region "mouse events" _ Public Enum MouseEventFlags As UInteger MOUSEEVENTF_ABSOLUTE = &H8000 @@ -19,25 +19,205 @@ Module input MOUSEEVENTF_HWHEEL = &H1000 End Enum + Public Const WHEEL_DELTA = 120 + _ - Private Sub mouse_event(dwFlags As UInteger, dx As Integer, dy As Integer, dwData As UInteger, dwExtraInfo As Integer) + Public Sub mouse_event(dwFlags As UInteger, dx As Integer, dy As Integer, dwData As Integer, dwExtraInfo As Integer) End Sub - Public Sub movemouse(dx As Integer, dy As Integer) - mouse_event(MouseEventFlags.MOUSEEVENTF_MOVE, dx, dy, 0, 0) +#End Region + +#Region "keyboard events" + + Enum VK + LBUTTON = 1 + RBUTTON = 2 + CANCEL_KEY = 3 + MBUTTON = 4 + XBUTTON1 = 5 + XBUTTON2 = 6 + KEY_BACK = 8 + TAB_KEY = 9 + CLEAR = 12 + RETURN_KEY = 13 + SHIFT = 16 + CONTROL = 17 + MENU = 18 + PAUSE = 19 + CAPITAL = 20 + KANA = 21 + HANGUL = 21 + JUNJA = 23 + FINAL = 24 + HANJA = 25 + KANJI = 25 + ESCAPE = 27 + CONVERT = 28 + NONCONVERT = 29 + ACCEPT = 30 + MODECHANGE = 31 + SPACE_KEY = 32 + PRIOR = 33 + NEXT_KEY = 34 + END_KEY = 35 + HOME = 36 + LEFT_KEY = 37 + UP = 38 + RIGHT_KEY = 39 + DOWN = 40 + SELECT_KEY = 41 + PRINT_KEY = 42 + EXECUTE = 43 + SNAPSHOT = 44 + INSERT = 45 + DELETE = 46 + HELP = 47 + KEY_0 = 48 + KEY_1 = 49 + KEY_2 = 50 + KEY_3 = 51 + KEY_4 = 52 + KEY_5 = 53 + KEY_6 = 54 + KEY_7 = 55 + KEY_8 = 56 + KEY_9 = 57 + KEY_A = 65 + KEY_B = 66 + KEY_C = 67 + KEY_D = 68 + KEY_E = 69 + KEY_F = 70 + KEY_G = 71 + KEY_H = 72 + KEY_I = 73 + KEY_J = 74 + KEY_K = 75 + KEY_L = 76 + KEY_M = 77 + KEY_N = 78 + KEY_O = 79 + KEY_P = 80 + KEY_Q = 81 + KEY_R = 82 + KEY_S = 83 + KEY_T = 84 + KEY_U = 85 + KEY_V = 86 + KEY_W = 87 + KEY_X = 88 + KEY_Y = 89 + KEY_Z = 90 + LWIN = 91 + RWIN = 92 + APPS = 93 + SLEEP = 95 + NUMPAD0 = 96 + NUMPAD1 = 97 + NUMPAD2 = 98 + NUMPAD3 = 99 + NUMPAD4 = 100 + NUMPAD5 = 101 + NUMPAD6 = 102 + NUMPAD7 = 103 + NUMPAD8 = 104 + NUMPAD9 = 105 + MULTIPLY = 106 + ADD = 107 + SEPARATOR = 108 + SUBTRACT = 109 + DECIMAL_KEY = 110 + DIVIDE = 111 + F1 = 112 + F2 = 113 + F3 = 114 + F4 = 115 + F5 = 116 + F6 = 117 + F7 = 118 + F8 = 119 + F9 = 120 + F10 = 121 + F11 = 122 + F12 = 123 + F13 = 124 + F14 = 125 + F15 = 126 + F16 = 127 + F17 = 128 + F18 = 129 + F19 = 130 + F20 = 131 + F21 = 132 + F22 = 133 + F23 = 134 + F24 = 135 + NUMLOCK = 144 + SCROLL = 145 + LSHIFT = 160 + RSHIFT = 161 + LCONTROL = 162 + RCONTROL = 163 + LMENU = 164 + RMENU = 165 + BROWSER_BACK = 166 + BROWSER_FORWARD = 167 + BROWSER_REFRESH = 168 + BROWSER_STOP = 169 + BROWSER_SEARCH = 170 + BROWSER_FAVORITES = 171 + BROWSER_HOME = 172 + VOLUME_MUTE = 173 + VOLUME_DOWN = 174 + VOLUME_UP = 175 + MEDIA_NEXT_TRACK = 176 + MEDIA_PREV_TRACK = 177 + MEDIA_STOP = 178 + MEDIA_PLAY_PAUSE = 179 + LAUNCH_MAIL = 180 + LAUNCH_MEDIA_SELECT = 181 + LAUNCH_APP1 = 182 + LAUNCH_APP2 = 183 + OEM_1 = 186 + OEM_PLUS = 187 + OEM_COMMA = 188 + OEM_MINUS = 189 + OEM_PERIOD = 190 + OEM_2 = 191 + OEM_3 = 192 + OEM_4 = 219 + OEM_5 = 220 + OEM_6 = 221 + OEM_7 = 222 + OEM_8 = 223 + OEM_102 = 226 + PROCESSKEY = 229 + PACKET = 231 + ATTN = 246 + CRSEL = 247 + EXSEL = 248 + EREOF = 249 + PLAY = 250 + ZOOM = 251 + NONAME = 252 + PA1 = 253 + OEM_CLEAR = 254 + End Enum + + Public Const KEYEVENTF_EXTENDEDKEY As UInteger = &H1 + Public Const KEYEVENTF_KEYUP As UInteger = &H2 + + + _ + Public Sub keybd_event(bVk As Byte, bScan As Byte, dwFlags As UInteger, dwExtraInfo As Integer) End Sub - Public Sub leftclick() - mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) + Public Sub keybd_press(bVK As Byte) + keybd_event(bVK, 0, 0, 0) System.Threading.Thread.Sleep(10) - mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) + keybd_event(bVK, 0, KEYEVENTF_KEYUP, 0) End Sub - Public Sub leftstart() - mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) - End Sub +#End Region - Public Sub leftrelease() - mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) - End Sub End Module diff --git a/webmouse/main.Designer.vb b/webmouse/main.Designer.vb index add36f1..f0a23cf 100755 --- a/webmouse/main.Designer.vb +++ b/webmouse/main.Designer.vb @@ -48,11 +48,12 @@ Partial Class main Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.LogText.Location = New System.Drawing.Point(12, 41) + Me.LogText.MaxLength = 1000 Me.LogText.Multiline = True Me.LogText.Name = "LogText" Me.LogText.ReadOnly = True Me.LogText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical - Me.LogText.Size = New System.Drawing.Size(531, 291) + Me.LogText.Size = New System.Drawing.Size(531, 94) Me.LogText.TabIndex = 1 ' 'Label1 @@ -96,7 +97,7 @@ Partial Class main ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(555, 344) + Me.ClientSize = New System.Drawing.Size(555, 147) Me.Controls.Add(Me.DragInput) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.TapInput) diff --git a/webmouse/main.vb b/webmouse/main.vb index 0fc1534..95958d5 100755 --- a/webmouse/main.vb +++ b/webmouse/main.vb @@ -2,6 +2,9 @@ Imports System.Net Public Class main Dim weblistener As HttpListener + Dim lastpos As New Point(0, 0) + Dim startpos As New Point(0, 0) + Dim leftclicking As Boolean = False Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles StartButton.Click If Not weblistener Is Nothing Then @@ -12,7 +15,7 @@ Public Class main StartButton.Text = "Start" Else weblistener = New HttpListener - weblistener.Prefixes.Add("http://+:8080/") + weblistener.Prefixes.Add("http://*:8080/") weblistener.Start() Dim listenthread As New Thread(AddressOf listenforconnection) listenthread.Start() @@ -24,11 +27,12 @@ Public Class main End Sub Public Sub listenforconnection() - Dim context As HttpListenerContext + Dim context As HttpListenerContext = Nothing Dim resp As HttpListenerResponse - Dim lastpos As New Point(0, 0) - Dim startpos As New Point(0, 0) + Dim respstr As String = String.Empty Dim lastpacket As Long = -1 + Dim lastpack As Long + Dim leftclicking As Boolean = False While weblistener.IsListening Try context = weblistener.GetContext() @@ -39,58 +43,29 @@ Public Class main End Try resp = context.Response Dim path As String = context.Request.Url.AbsolutePath - log(context.Request.RemoteEndPoint.ToString & " " & path) - + log(context.Request.RemoteEndPoint.ToString & " " & context.Request.RawUrl) ' check for valid command packets If path = "/" Then - Dim mainpagebytes As Byte() = FileIO.FileSystem.ReadAllBytes("page.html") - resp.OutputStream.Write(mainpagebytes, 0, mainpagebytes.Length) - resp.Close() + respstr = FileIO.FileSystem.ReadAllText("page.html") lastpacket = 0 - Continue While - - ElseIf path.StartsWith("/move/") Then - Dim x As Integer = path.Split("/")(2) - Dim y As Integer = path.Split("/")(3) - Dim pack As Long = path.Split("/")(4) - If pack > lastpacket Then - movemouse(x - lastpos.X, y - lastpos.Y) - lastpos.X = x - lastpos.Y = y - lastpacket = pack - End If - - ElseIf path.StartsWith("/start/") Then - Dim x As Integer = path.Split("/")(2) - Dim y As Integer = path.Split("/")(3) - Dim pack As Long = path.Split("/")(4) - If pack > lastpacket Then - lastpos.X = x - lastpos.Y = y - startpos.X = x - startpos.Y = y - lastpacket = pack - End If - - ElseIf path.StartsWith("/end/") Then - Dim x As Integer = path.Split("/")(2) - Dim y As Integer = path.Split("/")(3) - Dim pack As Long = path.Split("/")(4) - If pack > lastpacket Then - Dim tol As Integer = TapInput.Value - If (Math.Abs(x - startpos.X) < tol) And (Math.Abs(y - startpos.Y) < tol) Then - leftclick() - End If - lastpacket = pack + Else + Dim pack As Long = context.Request.QueryString("seq") + If pack > lastpack Then + respstr = handleinput(context.Request) + lastpack = pack End If End If - Dim respstr As String = "ok" - Dim respbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(respstr) - resp.OutputStream.Write(respbytes, 0, respbytes.Length) - resp.Close() - + If String.IsNullOrEmpty(respstr) Then + respstr = "bad" + End If + Dim respbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(respstr) + resp.ContentLength64 = respbytes.Length + resp.OutputStream.Write(respbytes, 0, respbytes.Length) + resp.OutputStream.Close() + resp.Close() + 'perftimer.Reset() End While End Sub @@ -105,8 +80,96 @@ Public Class main Button1_Click(sender, e) End Sub Private Sub log(str As String) - LogText.Text = Now.ToString("[HH:mm:ss.fff] ") & str & vbNewLine & LogText.Text + Dim oldtext As String = LogText.Text + Dim oldsplit() As String = oldtext.Split(vbNewLine) + Dim newtext As String + newtext = Now.ToString("[HH:mm:ss.fff] ") & str & vbNewLine + For i = 0 To Math.Min(oldsplit.Length - 1, 5) + newtext &= oldsplit(i) & vbNewLine + Next + + LogText.Text = newtext End Sub + Private Function handleinput(req As HttpListenerRequest) As String + Dim split() As String = req.Url.AbsolutePath.Split({"/"}, StringSplitOptions.RemoveEmptyEntries) + If split.Length < 1 Then + Return "bad" + End If + Dim opt As String = split(0) + + Select Case opt + + Case "start" 'start of trackpad touch + lastpos.X = req.QueryString("x") + lastpos.Y = req.QueryString("y") + startpos.X = req.QueryString("x") + startpos.Y = req.QueryString("y") + + Case "move" 'trackpad touch move + mouse_event(MouseEventFlags.MOUSEEVENTF_MOVE, req.QueryString("x") - lastpos.X, req.QueryString("y") - lastpos.Y, 0, 0) + lastpos.X = req.QueryString("x") + lastpos.Y = req.QueryString("y") + + Case "end" + Dim tol As Integer = TapInput.Value + If (Math.Abs(req.QueryString("x") - startpos.X) < tol) And (Math.Abs(req.QueryString("y") - startpos.Y) < tol) Then + mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) + System.Threading.Thread.Sleep(10) + mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) + End If + + Case "left" + If leftclicking Then + mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) + leftclicking = False + Else + mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) + leftclicking = True + End If + + Case "middle" + mouse_event(MouseEventFlags.MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0) + System.Threading.Thread.Sleep(10) + mouse_event(MouseEventFlags.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0) + + Case "right" + mouse_event(MouseEventFlags.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0) + System.Threading.Thread.Sleep(10) + mouse_event(MouseEventFlags.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0) + + Case "wheel" + mouse_event(MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, WHEEL_DELTA * req.QueryString("d"), 0) + + Case "volume" + If req.QueryString("d") = -1 Then + keybd_press(VK.VOLUME_DOWN) + ElseIf req.QueryString("d") = 0 Then + keybd_press(VK.VOLUME_MUTE) + ElseIf req.QueryString("d") = 1 Then + keybd_press(VK.VOLUME_UP) + End If + + Case "media" + Select Case req.QueryString("act") + Case "stop" + keybd_press(VK.MEDIA_STOP) + Case "prev" + keybd_press(VK.MEDIA_PREV_TRACK) + Case "play" + keybd_press(VK.MEDIA_PLAY_PAUSE) + Case "next" + keybd_press(VK.MEDIA_NEXT_TRACK) + End Select + + Case "text" + + Case Else + Return "bad" + + End Select + Return "ok" + End Function + End Class diff --git a/webmouse/webmouse.vbproj b/webmouse/webmouse.vbproj index 1f12efb..43f8fb5 100755 --- a/webmouse/webmouse.vbproj +++ b/webmouse/webmouse.vbproj @@ -98,6 +98,7 @@ Settings.settings True + @@ -111,7 +112,9 @@ - + + Designer + MyApplicationCodeGenerator Application.Designer.vb