Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions KeyboardMouseWin/KeyboardMouseWin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="FlaUI.UIA3" Version="4.0.0" />
<PackageReference Include="FontAwesome.WPF" Version="4.7.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="SharpHook" Version="5.2.0" />
<PackageReference Include="System.Reactive.Async" Version="6.0.0-alpha.18" />
Expand Down
1 change: 1 addition & 0 deletions KeyboardMouseWin/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace KeyboardMouseWin
/// </summary>
public partial class MainWindow : Window
{

public MainWindow()
{
InitializeComponent();
Expand Down
65 changes: 49 additions & 16 deletions KeyboardMouseWin/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
using KeyboardMouseWin.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SharpHook;
using System.Windows;

namespace KeyboardMouseWin
namespace KeyboardMouseWin;

public static class Program
{
public static class Program
[STAThread]
public static void Main(string[] args)
{
[STAThread]
public static void Main(string[] args)
var hostbuilder = new HostBuilder()
.ConfigureAppConfiguration((context, configurationBuilder) =>
{
configurationBuilder.SetBasePath(context.HostingEnvironment.ContentRootPath);
configurationBuilder.AddJsonFile("appsettings.json", optional: false);
})
.ConfigureServices((context, services) =>
{
services.Configure<Settings>(context.Configuration);

services.AddSingleton<TaskPoolGlobalHook>();
services.AddSingleton<MainWindow>();
services.AddSingleton<CaptionService>();
services.AddSingleton(sp =>
new CaptionViewModel(sp.GetRequiredService<CaptionService>(), new FlauiProvider(), sp.GetRequiredService<MainWindow>().Dispatcher));
})
.ConfigureLogging(logging =>
{
var hook = new TaskPoolGlobalHook();
hook.RunAsync();
var service = new CaptionService();
var window = new MainWindow();
var viewModel = new CaptionViewModel(service, new FlauiProvider(), window.Dispatcher);
hook.KeyPressed += async (_, e) => await viewModel.HandleKeyDown(SharpHookConverter.ToKey(e.Data.KeyCode), e);
hook.KeyReleased += (_, e) => viewModel.HandleKeyUp(SharpHookConverter.ToKey(e.Data.KeyCode));
window.DataContext = viewModel;
var application = new Application();
Task.Run(() => window.Dispatcher.Invoke(() => window.Hide()));
application.Run(window);
}
logging.AddConsole();
});

var host = hostbuilder.Build();

host.Start();



var hook = host.Services.GetRequiredService<TaskPoolGlobalHook>();
hook.RunAsync();

var viewModel = host.Services.GetRequiredService< CaptionViewModel>();
hook.KeyPressed += async (_, e) => await viewModel.HandleKeyDown(SharpHookConverter.ToKey(e.Data.KeyCode), e);
hook.KeyReleased += (_, e) => viewModel.HandleKeyUp(SharpHookConverter.ToKey(e.Data.KeyCode));

var window = host.Services.GetRequiredService<MainWindow>();
window.DataContext = viewModel;


var application = new Application();
Task.Run(() => window.Dispatcher.Invoke(() => window.Hide()));
application.Run(window);
}
}
42 changes: 29 additions & 13 deletions KeyboardMouseWin/WelcomeWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:WelcomeWindowViewModel}"
Title="Welcome" Height="450" Width="800">
<Window.Icon>
<DrawingImage />
</Window.Icon>
<Window.Resources>
<Viewbox x:Key="KeyboardShortcut" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Width="1006.11" Height="1009.31">
<Canvas Width="1006.11" Height="1009.31">
<Canvas Width="640" Height="480">
<Polyline Points="961.89,152.12 961.89,965.09 148.92,965.09" Stroke="#33af83" StrokeThickness="88.44" StrokeLineJoin="Round"/>
<Polyline Points="857.19,44.22 44.22,44.22 44.22,857.19" Stroke="#33af83" StrokeThickness="88.44" StrokeLineJoin="Round"/>
<Polyline Points="644.99,549.11 645.75,285.72 370.59,286.46" Stroke="#e53f7b" StrokeThickness="88.44" StrokeLineJoin="Round"/>
Expand All @@ -19,26 +22,38 @@
</Window.Resources>
<Window.Content>
<DockPanel>
<DockPanel DockPanel.Dock="Left"
VerticalAlignment="Bottom"
MinHeight="200"
MinWidth="200">
<DockPanel.Background>
<VisualBrush Visual="{StaticResource KeyboardShortcut}"
Stretch="Uniform"
AutoLayoutContent="True"
AlignmentX="Left"
AlignmentY="Top" />
</DockPanel.Background>
</DockPanel>
<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" Text="Welcome"/>

<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16">
<Run Text="To show possible Keyboards please Press: "/>
<Run FontWeight="Bold" Text="{Binding Settings.CaptionKeyCombination}" />
<Run Text="To show possible Keyboards please Press: "/>
<Run FontWeight="Bold" Text="{Binding Settings.CaptionKeyCombination}" />
</TextBlock>

<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16">
<Run Text="To exit from the Shortcuts Press: "/>
<Run FontWeight="Bold" Text="{Binding Settings.ClearKeyCombiantion}" />
<Run Text="To exit from the Shortcuts Press: "/>
<Run FontWeight="Bold" Text="{Binding Settings.ClearKeyCombiantion}" />
</TextBlock>

<StackPanel DockPanel.Dock="Bottom"
HorizontalAlignment="Right" VerticalAlignment="Bottom"
Orientation="Horizontal"
Margin="10">
HorizontalAlignment="Right" VerticalAlignment="Bottom"
Orientation="Horizontal"
Margin="10">
<TextBlock Text="Please restart the app after changing the config" />
<Button Content="Change Shortcuts"
Command="{Binding Path=EditShortCuts}"
Margin="10,0,0,0">
Command="{Binding Path=EditShortCuts}"
Margin="10,0,0,0">
<Button.ToolTip>
<ToolTip>
<TextBlock Text="Please restart the application to reload the configuration."/>
Expand All @@ -47,10 +62,11 @@
</Button>
</StackPanel>
<Button DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10"
Content="Exit Keyboard Shortcut"
Command="{Binding Path=CloseWindow}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
Content="Exit Keyboard Shortcut"
Command="{Binding Path=CloseWindow}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
</Button>

</DockPanel>
</Window.Content>
</Window>
14 changes: 14 additions & 0 deletions KeyboardMouseWin/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace"
},
"Console": {
"LogLevel": {
"Default": "Trace"
},
"IncludeScopes": true,
"TimestampFormat": "HH:mm:ss"
}
}
}