Skip to content

Commit

Permalink
Moved common files to external library. Support for Secondary Enter b…
Browse files Browse the repository at this point in the history
…ehaviour
  • Loading branch information
BarRaider committed Jan 17, 2019
1 parent f91fa84 commit 559c69f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 86 deletions.
4 changes: 3 additions & 1 deletion DelayedText/DelayedText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="barraider-sdtools">
<HintPath>..\..\barraider-sdtools\barraider-sdtools\bin\Release\barraider-sdtools.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=2.4.3.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.4.3\lib\netstandard2.0\CommandLine.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -63,7 +66,6 @@
<Compile Include="PluginContainer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StreamDeckOptions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
95 changes: 39 additions & 56 deletions DelayedText/DelayedTextInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using BarRaider.SdTools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand All @@ -10,9 +11,9 @@

namespace Delayedtext
{
public class DelayedTextInput
public class DelayedTextInput : IPluginable
{
private class InspectorSettings
private class InspectorSettings : SettingsBase
{
public static InspectorSettings CreateDefaultSettings()
{
Expand All @@ -24,22 +25,6 @@ public static InspectorSettings CreateDefaultSettings()
return instance;
}

public async void SendToPropertyInspectorAsync()
{
if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(ActionId))
{
await StreamDeckConnection.SendToPropertyInspectorAsync(ActionId, JObject.FromObject(this), this.ContextId);
}
}

public async void SetSettingsAsync()
{
if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(ActionId))
{
await StreamDeckConnection.SetSettingsAsync(JObject.FromObject(this), this.ContextId);
}
}

[JsonProperty(PropertyName = "inputText")]
public string InputText { get; set; }

Expand All @@ -48,15 +33,6 @@ public async void SetSettingsAsync()

[JsonProperty(PropertyName = "enterMode")]
public bool EnterMode { get; set; }

[JsonIgnore]
public string ActionId { private get; set; }

[JsonIgnore]
public string ContextId { private get; set; }

[JsonIgnore]
public streamdeck_client_csharp.StreamDeckConnection StreamDeckConnection { private get; set; }
}

#region Private members
Expand Down Expand Up @@ -96,37 +72,11 @@ public void KeyPressed()
SendInput();
}

private async void SendInput()
public void KeyReleased()
{
inputRunning = true;
await Task.Run(() =>
{
InputSimulator iis = new InputSimulator();
string text = settings.InputText;
int delay = settings.Delay;
if (settings.EnterMode)
{
text = text.Replace("\r\n", "\n");
}
for (int idx = 0; idx < text.Length; idx++)
{
if (settings.EnterMode && text[idx] == '\n')
{
iis.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
}
else
{
iis.Keyboard.TextEntry(text[idx]);
}
Thread.Sleep(delay);
}
});
inputRunning = false;
}

public void KeyReleased()
public void OnTick()
{
}

Expand Down Expand Up @@ -155,5 +105,38 @@ public void UpdateSettings(JObject payload)
}

#endregion

#region Private Methods

private async void SendInput()
{
inputRunning = true;
await Task.Run(() =>
{
InputSimulator iis = new InputSimulator();
string text = settings.InputText;
int delay = settings.Delay;
if (settings.EnterMode)
{
text = text.Replace("\r\n", "\n");
}
for (int idx = 0; idx < text.Length; idx++)
{
if (settings.EnterMode && text[idx] == '\n')
{
iis.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
}
else
{
iis.Keyboard.TextEntry(text[idx]);
}
Thread.Sleep(delay);
}
});
inputRunning = false;
}
#endregion
}
}
5 changes: 3 additions & 2 deletions DelayedText/PluginContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using BarRaider.SdTools;
using Newtonsoft.Json;
using streamdeck_client_csharp;
using streamdeck_client_csharp.Events;
using System;
Expand All @@ -18,7 +19,7 @@ class PluginContainer
private SemaphoreSlim instancesLock = new SemaphoreSlim(1);

// Holds all instances of plugin
private static Dictionary<string, DelayedTextInput> instances = new Dictionary<string, DelayedTextInput>();
private static Dictionary<string, IPluginable> instances = new Dictionary<string, IPluginable>();


public void Run(StreamDeckOptions options)
Expand Down
3 changes: 2 additions & 1 deletion DelayedText/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommandLine;
using BarRaider.SdTools;
using CommandLine;
using System;

namespace Delayedtext
Expand Down
2 changes: 1 addition & 1 deletion DelayedText/PropertyInspector/DelayedText/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<body>
<div class="sdpi-wrapper">
<details class="message info">
<summary>For feedback/suggestions contact me at <a href="https://BarRaider.github.io" target="_blank">https://BarRaider.github.io</a> </summary>
<summary>For feedback/suggestions contact me at <a href="https://BarRaider.github.io" target="_blank" onclick="openWebsite()">https://BarRaider.github.io</a> </summary>
</details>
<div type="textarea" class="sdpi-item" id="inputText_div">
<div class="sdpi-item-label">Text</div>
Expand Down
12 changes: 12 additions & 0 deletions DelayedText/PropertyInspector/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ function sendPayloadToPlugin(payload) {
}
}

function openWebsite() {
if (websocket && (websocket.readyState === 1)) {
const json = {
'event': 'openUrl',
'payload': {
'url': 'https://BarRaider.github.io'
}
};
websocket.send(JSON.stringify(json));
}
}

// our method to pass values to the plugin
function sendValueToPlugin(value, param) {
if (websocket && (websocket.readyState === 1)) {
Expand Down
24 changes: 0 additions & 24 deletions DelayedText/StreamDeckOptions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion DelayedText/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"Name": "Delayed Text Input",
"Icon": "Images/pluginIcon",
"URL": "https://barraider.github.io/",
"Version": "1.0",
"Version": "1.01",
"CodePath": "com.barraider.delayedtext",
"Category": "BarRaider",
"CategoryIcon": "Images/categoryIcon",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This library uses the [streamdeck-client-csharp](https://github.com/TyrenDe/stre
## Current functionality
- Simulates keyboard input
- You can choose the delay between each character (between 1ms to 2000ms)
- **New in v1.01** Secondary behaviour for ENTER key (to support additional games)

## Feature roadmap
Always open to more suggestions.
Expand Down

0 comments on commit 559c69f

Please sign in to comment.