Skip to content

Commit 7f20e09

Browse files
authored
Merge pull request #21 from Terence-D/fix-key-pressing
Fix key pressing
2 parents 3161cb7 + e8d66e4 commit 7f20e09

File tree

6 files changed

+128
-46
lines changed

6 files changed

+128
-46
lines changed
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using GameInputCommandSystem.Models;
2-
using System.Collections.Generic;
3-
using System.Net;
4-
using System.Net.Http;
52
using System.Web.Http;
63

74
/**
@@ -24,28 +21,10 @@ namespace GameInputCommandSystem.Controllers
2421
[Authorize]
2522
public class KeyController : ApiController
2623
{
27-
private KeyMaster km = new KeyMaster();
28-
29-
//// GET api/key/5
30-
//public HttpResponseMessage Get(char id)
31-
//{
32-
// Command test = new Command();
33-
// test.Key = id.ToString();
34-
// sendCommand(test);
35-
// List<Command> responses = new List<Command>();
36-
// responses.Add(new Command());
37-
// return Request.CreateResponse(HttpStatusCode.OK, responses, Configuration.Formatters.JsonFormatter);
38-
//}
39-
4024
// POST api/key
4125
public void Post([FromBody]Command value)
4226
{
43-
sendCommand(value);
44-
}
45-
46-
private void sendCommand(Command value)
47-
{
48-
km.SendCommand(value);
27+
KeyMaster.SendCommand(value, false);
4928
}
5029
}
5130
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using GameInputCommandSystem.Models;
2+
using System.Web.Http;
3+
4+
/**
5+
Copyright [2019] [Terence Doerksen]
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
namespace GameInputCommandSystem.Controllers
20+
{
21+
[Authorize]
22+
public class ToggleController : ApiController
23+
{
24+
// POST api/toggle
25+
public void Post([FromBody]Command value)
26+
{
27+
KeyMaster.SendCommand(value, true);
28+
}
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net.Http;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Web.Http;
8+
using System.Reflection;
9+
using System.Diagnostics;
10+
using System.Net;
11+
12+
namespace GameInputCommandSystem.Controllers
13+
{
14+
public class VersionController : ApiController
15+
{
16+
// Get api/version
17+
public HttpResponseMessage Get()
18+
{
19+
Assembly assembly = Assembly.GetExecutingAssembly();
20+
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
21+
string version = fileVersionInfo.ProductVersion;
22+
23+
return Request.CreateResponse(HttpStatusCode.OK, version, Configuration.Formatters.JsonFormatter);
24+
}
25+
}
26+
}

GameInputCommandSystem/GameInputCommandSystem.csproj

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<MapFileExtensions>true</MapFileExtensions>
2727
<AutorunEnabled>true</AutorunEnabled>
2828
<ApplicationRevision>0</ApplicationRevision>
29-
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
29+
<ApplicationVersion>1.3.0.%2a</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<PublishWizardCompleted>true</PublishWizardCompleted>
3232
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -92,7 +92,8 @@
9292
<ApplicationIcon>app.ico</ApplicationIcon>
9393
</PropertyGroup>
9494
<ItemGroup>
95-
<Reference Include="AutoItX3.Assembly">
95+
<Reference Include="AutoItX3.Assembly, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a646454c8d475470, processorArchitecture=MSIL">
96+
<SpecificVersion>False</SpecificVersion>
9697
<HintPath>C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.Assembly.dll</HintPath>
9798
</Reference>
9899
<Reference Include="Microsoft.Owin, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -160,6 +161,8 @@
160161
<SubType>Code</SubType>
161162
</Compile>
162163
<Compile Include="Controllers\KeyController.cs" />
164+
<Compile Include="Controllers\ToggleController.cs" />
165+
<Compile Include="Controllers\VersionController.cs" />
163166
<Compile Include="GateKeeper.cs" />
164167
<Compile Include="GICValues.cs" />
165168
<Compile Include="GlobalSuppressions.cs" />
@@ -225,5 +228,16 @@
225228
<Install>false</Install>
226229
</BootstrapperPackage>
227230
</ItemGroup>
231+
<ItemGroup>
232+
<COMReference Include="AutoItX3Lib">
233+
<Guid>{F8937E53-D444-4E71-9275-35B64210CC3B}</Guid>
234+
<VersionMajor>1</VersionMajor>
235+
<VersionMinor>0</VersionMinor>
236+
<Lcid>0</Lcid>
237+
<WrapperTool>tlbimp</WrapperTool>
238+
<Isolated>False</Isolated>
239+
<EmbedInteropTypes>True</EmbedInteropTypes>
240+
</COMReference>
241+
</ItemGroup>
228242
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
229243
</Project>

GameInputCommandSystem/KeyMaster.cs

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using AutoIt;
22
using GameInputCommandSystem.Models;
3+
using System;
4+
using System.Windows;
35

46
/**
57
Copyright [2019] [Terence Doerksen]
@@ -18,35 +20,66 @@ limitations under the License.
1820
*/
1921
namespace GameInputCommandSystem
2022
{
21-
class KeyMaster
23+
public static class KeyMaster
2224
{
23-
public bool SendCommand(Command command)
25+
static volatile object locker = new Object();
26+
27+
public static bool SendCommand(Command command, bool quickCommand)
2428
{
25-
int rv = AutoItX.WinActivate(GICValues.Instance.Application);
26-
if (rv == 0)
29+
lock (locker)
2730
{
28-
return false;
29-
} else {
30-
if (command.activatorType == Command.KEY_DOWN) {
31-
//if any modifiers, send them first
32-
foreach (string modifier in command.Modifier)
31+
//long sec = DateTime.Now.Second;
32+
//Console.WriteLine("starting command for " + command.Key + " " + sec);
33+
int rv = 0;
34+
try
35+
{
36+
rv = AutoItX.WinWaitActive(GICValues.Instance.Application);
37+
}
38+
catch (Exception e)
39+
{
40+
//MessageBox.Show(e.Message);
41+
return false;
42+
}
43+
if (rv == 0)
44+
{
45+
return false;
46+
}
47+
else
48+
{
49+
if (command.activatorType == Command.KEY_DOWN)
3350
{
34-
AutoItX.Send("{" + modifier + "DOWN}");
51+
//if any modifiers, send them first
52+
foreach (string modifier in command.Modifier)
53+
{
54+
AutoItX.Send("{" + modifier + "DOWN}");
55+
}
56+
//now send the key itself
57+
AutoItX.Send("{" + command.Key + " down}");
58+
if (quickCommand)
59+
{
60+
//keep everything pressed for 10ms
61+
System.Threading.Thread.Sleep(10);
62+
AutoItX.Send("{" + command.Key + " up}");
63+
//if any modifiers, unset them last
64+
foreach (string modifier in command.Modifier)
65+
{
66+
AutoItX.Send("{" + modifier + "UP}");
67+
}
68+
}
3569
}
36-
//now send the key itself
37-
AutoItX.Send("{" + command.Key + " down}");
38-
//keep everything pressed for 10ms
39-
}
40-
else if (command.activatorType == Command.KEY_UP) {
41-
AutoItX.Send("{" + command.Key + " up}");
42-
//if any modifiers, unset them last
43-
foreach (string modifier in command.Modifier)
70+
else if (command.activatorType == Command.KEY_UP && !quickCommand )
4471
{
45-
AutoItX.Send("{" + modifier + "UP}");
72+
AutoItX.Send("{" + command.Key + " up}");
73+
//if any modifiers, unset them last
74+
foreach (string modifier in command.Modifier)
75+
{
76+
AutoItX.Send("{" + modifier + "UP}");
77+
}
4678
}
79+
//Console.WriteLine("ending command for " + command.Key + " " + sec);
4780
}
81+
return true;
4882
}
49-
return true;
5083
}
5184
}
5285
}

GameInputCommandSystem/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.1.0.0")]
55-
[assembly: AssemblyFileVersion("1.1.0.0")]
54+
[assembly: AssemblyVersion("1.3.0.0")]
55+
[assembly: AssemblyFileVersion("1.3.0.0")]

0 commit comments

Comments
 (0)