Rewrote a lot of the interaction code to make it easier to modify by the end-user.

Added a readme explaining the above.
Added YouTube key controls to the default page.
Added a setting to save tap tolerance between restarts.
This commit is contained in:
moosecrab 2020-06-17 02:35:33 -07:00
parent 0e3bed62dc
commit 3eb86784b6
7 changed files with 153 additions and 80 deletions

View File

@ -13,6 +13,9 @@
<setting name="listenport" serializeAs="String">
<value>8080</value>
</setting>
<setting name="taptolerance" serializeAs="String">
<value>5</value>
</setting>
</webcrab.My.MySettings>
</userSettings>
</configuration>

View File

@ -65,6 +65,18 @@ Namespace My
Me("listenport") = value
End Set
End Property
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("5")> _
Public Property taptolerance() As Integer
Get
Return CType(Me("taptolerance"),Integer)
End Get
Set
Me("taptolerance") = value
End Set
End Property
End Class
End Namespace

View File

@ -5,5 +5,8 @@
<Setting Name="listenport" Type="System.UInt16" Scope="User">
<Value Profile="(Default)">8080</Value>
</Setting>
<Setting Name="taptolerance" Type="System.Int32" Scope="User">
<Value Profile="(Default)">5</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -5,7 +5,7 @@ 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
Dim nexttoggleclick As UInteger = MouseEventFlags.MOUSEEVENTF_LEFTDOWN Or MouseEventFlags.MOUSEEVENTF_RIGHTDOWN Or MouseEventFlags.MOUSEEVENTF_MIDDLEDOWN Or MouseEventFlags.MOUSEEVENTF_XDOWN
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles StartButton.Click
If Not weblistener Is Nothing Then
@ -19,9 +19,13 @@ Public Class main
Else
Dim listenport As UShort = My.Settings("listenport")
PortInput.Value = listenport
weblistener = New HttpListener
weblistener.Prefixes.Add("http://*:" & listenport & "/")
weblistener.Start()
Try
weblistener = New HttpListener
weblistener.Prefixes.Add("http://*:" & listenport & "/")
weblistener.Start()
Catch ex As Exception
log(ex.ToString)
End Try
Dim listenthread As New Thread(AddressOf listenforconnection)
listenthread.Start()
log("Started")
@ -75,6 +79,7 @@ Public Class main
End Sub
Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
My.Settings.taptolerance = TapInput.Value
If Not weblistener Is Nothing Then
weblistener.Abort()
End If
@ -82,6 +87,8 @@ Public Class main
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
Dim taptolerance As Integer = My.Settings.taptolerance
TapInput.Value = taptolerance
Button1_Click(sender, e)
End Sub
Private Sub log(str As String)
@ -124,61 +131,67 @@ Public Class main
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)
Case "click"
Dim eventflag As UInteger = 0
Select Case req.QueryString("button")
Case "left"
eventflag = MouseEventFlags.MOUSEEVENTF_LEFTDOWN
Case "right"
eventflag = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN
Case "middle"
eventflag = MouseEventFlags.MOUSEEVENTF_MIDDLEDOWN
Case "x"
eventflag = MouseEventFlags.MOUSEEVENTF_XDOWN
Case Else
Return "unknown mouse button"
End Select
mouse_event(eventflag, 0, 0, 0, 0)
System.Threading.Thread.Sleep(10)
mouse_event(MouseEventFlags.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
' bit shift to the left is the corresponding button up event
mouse_event(eventflag << 1, 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 "toggle"
Dim eventflagmask As UInteger = 0
'buttonmask is just the 2 bits for the selected button
Select Case req.QueryString("button")
Case "left"
eventflagmask = MouseEventFlags.MOUSEEVENTF_LEFTDOWN Or MouseEventFlags.MOUSEEVENTF_LEFTUP
Case "right"
eventflagmask = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN Or MouseEventFlags.MOUSEEVENTF_RIGHTUP
Case "middle"
eventflagmask = MouseEventFlags.MOUSEEVENTF_MIDDLEDOWN Or MouseEventFlags.MOUSEEVENTF_MIDDLEUP
Case "x"
eventflagmask = MouseEventFlags.MOUSEEVENTF_XDOWN Or MouseEventFlags.MOUSEEVENTF_XUP
Case Else
Return "unknown mouse button"
End Select
'nexttoggleclick is either button up or down for each button
mouse_event(eventflagmask And nexttoggleclick, 0, 0, 0, 0)
'invert nexttoggleclick for the selected button only
nexttoggleclick = nexttoggleclick Xor eventflagmask
Case "wheel"
mouse_event(MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, WHEEL_DELTA * req.QueryString("d"), 0)
Dim eventflag As UInteger = 0
Select Case req.QueryString("axis")
Case "vert"
eventflag = MouseEventFlags.MOUSEEVENTF_WHEEL
Case "horiz"
eventflag = MouseEventFlags.MOUSEEVENTF_HWHEEL
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
mouse_event(eventflag, 0, 0, req.QueryString("delta"), 0)
Case "key"
Select Case req.QueryString("k")
Case "del"
keybd_press(VK.DELETE)
Case "bksp"
keybd_press(VK.KEY_BACK)
Case "enter"
keybd_press(VK.RETURN_KEY)
End Select
Try
Dim vk As Byte = req.QueryString("code")
keybd_press(vk)
Catch ex As Exception
log(ex.ToString)
End Try
Case "text"
Dim encodedtext As String = req.QueryString("t")
Dim encodedtext As String = req.QueryString("text")
Dim decodedtext As String = Uri.UnescapeDataString(encodedtext)
Try
SendKeysEscaped(decodedtext)
@ -186,6 +199,14 @@ Public Class main
log(ex.ToString)
End Try
Case "sendkeys"
Dim keys As String = req.QueryString("keys")
Try
SendKeys.SendWait(keys)
Catch ex As Exception
log(ex.ToString)
End Try
Case Else
Return "bad"

View File

@ -14,6 +14,9 @@ body {
margin: 0;
background-color: black;
color: gray;
display: flex;
flex-direction: column;
}
button{
text-align: center;
@ -27,12 +30,7 @@ button{
button:active {
background-color: silver;
}
button:focus, button:hover, button:focus-visible {
}
.touchpad {
height: 60%;
display: flex;
}
#canvas {
@ -40,12 +38,10 @@ button:focus, button:hover, button:focus-visible {
background-color: #111;
outline: gray solid 1px;
}
.buttonrow {
height: 10%;
div{
display: flex;
align-items: stretch;
}
.buttonrow input{
input{
background-color: #111;
color: gray;
outline: gray solid 1px;
@ -55,34 +51,40 @@ button:focus, button:hover, button:focus-visible {
</style>
</head>
<body>
<div class="buttonrow">
<div style="flex:2">
<button style="flex:1">menu</button>
<button onclick="sendmessage('key', 'k=del')" style="flex:1">del</button>
<button onclick="sendmessage('key', 'k=bksp')" style="flex:1">bksp</button>
<button onclick="sendmessage('key', 'k=enter')" style="flex:1">enter</button>
<button onclick="sendmessage('key', 'code=46')" style="flex:1">del</button>
<button onclick="sendmessage('key', 'code=8')" style="flex:1">bksp</button>
<button onclick="sendmessage('key', 'code=13')" style="flex:1">enter</button>
<input id="typebox" placeholder="type here" size=8 style="flex:2">
</div>
<div class="touchpad">
<div style="flex:1">
<button onclick="sendmessage('sendkeys', 'keys=j')" style="flex:1">j</button>
<button onclick="sendmessage('sendkeys', 'keys={LEFT}')" style="flex:1">&larr;</button>
<button onclick="sendmessage('sendkeys', 'keys=k')" style="flex:1">k</button>
<button onclick="sendmessage('sendkeys', 'keys={RIGHT}')" style="flex:1">&rarr;</button>
<button onclick="sendmessage('sendkeys', 'keys=l')" style="flex:1">l</button>
</div>
<div style="flex:12">
<span id="canvas"></span>
</div>
<div class="buttonrow">
<button onclick="sendmessage('left', '')" style="flex:2">left (toggle)</button>
<button onclick="sendmessage('wheel', 'd=1')" style="flex:1">up</button>
<button onclick="sendmessage('middle', '')" style="flex:1">mid</button>
<button onclick="sendmessage('wheel', 'd=-1')" style="flex:1">dn</button>
<button onclick="sendmessage('right', '')" style="flex:2">right</button>
<div style="flex:2">
<button onclick="sendmessage('toggle', 'button=left')" style="flex:2">left (toggle)</button>
<button onclick="sendmessage('wheel', 'axis=vert&delta=120')" style="flex:1">up</button>
<button onclick="sendmessage('click', 'button=middle')" style="flex:1">mid</button>
<button onclick="sendmessage('wheel', 'axis=vert&delta=-120')" style="flex:1">dn</button>
<button onclick="sendmessage('click', 'button=right')" style="flex:2">right</button>
</div>
<div class="buttonrow">
<button onclick="sendmessage('volume', 'd=-1')" style="flex:2">vol -</button>
<button onclick="sendmessage('volume', 'd=0')" style="flex:1">mute</button>
<button onclick="sendmessage('volume', 'd=1')" style="flex:2">vol +</button>
<!--<button onclick="sendmessage('volume', 1, 0)" style="flex:2">vol +</button>-->
<div style="flex:2">
<button onclick="sendmessage('key', 'code=174')" style="flex:2">vol -</button>
<button onclick="sendmessage('key', 'code=173')" style="flex:1">mute</button>
<button onclick="sendmessage('key', 'code=175')" style="flex:2">vol +</button>
</div>
<div class="buttonrow">
<button onclick="sendmessage('media', 'act=stop')" style="flex:1">stop</button>
<button onclick="sendmessage('media', 'act=prev')" style="flex:1">prev</button>
<button onclick="sendmessage('media', 'act=play')" style="flex:1">play/pause</button>
<button onclick="sendmessage('media', 'act=next')" style="flex:1">next</button>
<div style="flex:2">
<button onclick="sendmessage('key', 'code=178')" style="flex:1">stop</button>
<button onclick="sendmessage('key', 'code=177')" style="flex:1">prev</button>
<button onclick="sendmessage('key', 'code=179')" style="flex:1">play/pause</button>
<button onclick="sendmessage('key', 'code=176')" style="flex:1">next</button>
</div>
<script>
function startup() {
@ -147,7 +149,7 @@ function handleCancel(evt) {
function handlekeypress(evt) {
evt.preventDefault();
sendmessage("text", "t=" + encodeURIComponent(evt.target.value));
sendmessage("text", "text=" + encodeURIComponent(evt.target.value));
evt.target.value = "";
}

31
webcrab/res/readme.txt Executable file
View File

@ -0,0 +1,31 @@
Page.html is the page sent to the browser when the control site is opened.
It is easy to customize to add or remove buttons, actions, clicks, etc. to your page.
The PC side of the program recognizes several actions.
Mouse messages are:
start - start a trackpad movement
move - continue a trackpad movement
end - end a trackpad movement
All of the above take 2 arguments: x and y.
Mouse movement is relative so don't worry about the absolute values.
X is positive left, and Y is positive down.
Mouse button messages are:
click - click and release a mouse button
toggle - toggle a mouse button to either the clicked or released state
Both take a single argument: "button", which can be any of "left", "right", "middle", or "x".
Mouse wheel is a single message type:
wheel - command a mouse wheel movement
It takes two arguments: "axis" which is either "vert" or "horiz", and "delta" which is how far the wheel moves.
The default delta in Windows is 120.
Vert is positive away from the user, horiz is positive to the right.
Keyboard input has several message types:
key - send a single keystroke via the numeric key code (argument "code")
text - send raw typed text (argument "text", make sure to use encodeURIComponent() or similar)
sendkeys - send typed text but escaped according to the SendKeys() method (argument "keys")
"key" can be used to send off keys such as media and IME keys not available through the other methods. A full list of codes is here: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
"text" sends raw text, such as those typed using the phone keyboard.
"sendkeys" send keystrokes, but can use modifiers or non-text keys using escape characters. See more information here: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.devices.keyboard.sendkeys

View File

@ -153,6 +153,7 @@
<Content Include="res\page.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="res\readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.