Permalink
Browse files

Add project files & submodule.

  • Loading branch information...
1 parent a3d7fec commit 54f501f50c937e90fedbb32060fb4e0acfa2dce3 @Grabacr07 committed Sep 7, 2015
View
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+#* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
View
@@ -0,0 +1,3 @@
+[submodule "source/VirtualDesktop"]
+ path = source/VirtualDesktop
+ url = https://github.com/Grabacr07/VirtualDesktop
View
@@ -0,0 +1,54 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SylphyHorn", "SylphyHorn\SylphyHorn.csproj", "{5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VirtualDesktop", "VirtualDesktop", "{65847316-DFF7-497E-8542-B1F5E75803A1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualDesktop", "VirtualDesktop\source\VirtualDesktop\VirtualDesktop.csproj", "{AB848ECD-76AA-41C0-B63D-86A8591B25AA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualDesktop.WPF", "VirtualDesktop\source\VirtualDesktop.WPF\VirtualDesktop.WPF.csproj", "{9DD597C6-065A-4764-A96C-1B18C4EDED78}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Debug|x64.ActiveCfg = Debug|x64
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Debug|x64.Build.0 = Debug|x64
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Release|x64.ActiveCfg = Release|x64
+ {5B1F3C87-DE54-4BFD-86C9-87181F7FDC2D}.Release|x64.Build.0 = Release|x64
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Debug|x64.ActiveCfg = Debug|x64
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Debug|x64.Build.0 = Debug|x64
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Release|x64.ActiveCfg = Release|x64
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA}.Release|x64.Build.0 = Release|x64
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Debug|x64.ActiveCfg = Debug|x64
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Debug|x64.Build.0 = Debug|x64
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Release|x64.ActiveCfg = Release|x64
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {AB848ECD-76AA-41C0-B63D-86A8591B25AA} = {65847316-DFF7-497E-8542-B1F5E75803A1}
+ {9DD597C6-065A-4764-A96C-1B18C4EDED78} = {65847316-DFF7-497E-8542-B1F5E75803A1}
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
+ </startup>
+</configuration>
@@ -0,0 +1,8 @@
+<Application x:Class="SylphyHorn.Application"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="clr-namespace:SylphyHorn">
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Windows;
+using WindowsDesktop;
+using Livet;
+using MetroTrilithon.Lifetime;
+using StatefulModel;
+using SylphyHorn.Models;
+
+namespace SylphyHorn
+{
+ sealed partial class Application : IDisposableHolder
+ {
+ private readonly CompositeDisposable compositeDisposable = new CompositeDisposable();
+ private HookService hookService;
+
+ static Application()
+ {
+ AppDomain.CurrentDomain.UnhandledException += (sender, args) => ReportException(sender, args.ExceptionObject as Exception);
+ }
+
+ protected override void OnStartup(StartupEventArgs e)
+ {
+#if !DEBUG
+ var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this);
+ if (appInstance.IsFirst)
+#endif
+ {
+ this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
+ this.DispatcherUnhandledException += (sender, args) =>
+ {
+ ReportException(sender, args.Exception);
+ args.Handled = true;
+ };
+
+ DispatcherHelper.UIDispatcher = this.Dispatcher;
+ this.MainWindow = new MainWindow();
+ this.MainWindow.Show();
+
+ if (VirtualDesktop.IsSupported)
+ {
+ this.hookService = new HookService();
+ }
+ else { }
+ }
+#if !DEBUG
+ else
+ {
+ appInstance.SendCommandLineArgs(e.Args);
+ this.Shutdown();
+ }
+#endif
+
+ base.OnStartup(e);
+ }
+
+
+ private static void ReportException(object sender, Exception exception)
+ {
+ #region const
+
+ const string messageFormat = @"
+===========================================================
+ERROR, date = {0}, sender = {1},
+{2}
+";
+ const string path = "error.log";
+
+ #endregion
+
+ // ToDo: 例外ダイアログ
+
+ try
+ {
+ var message = string.Format(messageFormat, DateTimeOffset.Now, sender, exception);
+
+ Debug.WriteLine(message);
+ File.AppendAllText(path, message);
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
+
+ // とりあえずもう終了させるしかないもじゃ
+ // 救えるパターンがあるなら救いたいけど方法わからんもじゃ
+ Current.Shutdown();
+ }
+
+ #region IDisposable members
+
+ ICollection<IDisposable> IDisposableHolder.CompositeDisposable => this.compositeDisposable;
+
+ void IDisposable.Dispose()
+ {
+ this.compositeDisposable.Dispose();
+ }
+
+ #endregion
+ }
+}
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SylphyHorn.Interop
+{
+ public static class NativeMethods
+ {
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetForegroundWindow();
+
+ [DllImport("user32.dll")]
+ public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
+ }
+}
@@ -0,0 +1,12 @@
+<Window x:Class="SylphyHorn.MainWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:local="clr-namespace:SylphyHorn"
+ mc:Ignorable="d"
+ Title="MainWindow" Height="350" Width="525">
+ <Grid>
+
+ </Grid>
+</Window>
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Open.WinKeyboardHook;
+using SylphyHorn.Models;
+
+namespace SylphyHorn
+{
+ /// <summary>
+ /// MainWindow.xaml の相互作用ロジック
+ /// </summary>
+ public partial class MainWindow
+ {
+ public MainWindow()
+ {
+ this.InitializeComponent();
+ }
+ }
+}
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Input;
+using MetroTrilithon.Linq;
+using Open.WinKeyboardHook;
+
+namespace SylphyHorn.Models
+{
+ public class GlobalKeyHook
+ {
+ private readonly IKeyboardInterceptor interceptor = new KeyboardInterceptor();
+ private readonly HashSet<Key> pressedModifiers = new HashSet<Key>();
+
+ public event EventHandler<ShortcutKey> Pressed;
+
+ public GlobalKeyHook()
+ {
+ this.interceptor.KeyDown += this.InterceptorOnKeyDown;
+ this.interceptor.KeyUp += this.InterceptorOnKeyUp;
+ }
+
+ public void Start()
+ {
+ this.interceptor.StartCapturing();
+ }
+
+ public void Stop()
+ {
+ this.interceptor.StopCapturing();
+ }
+
+ private void InterceptorOnKeyDown(object sender, System.Windows.Forms.KeyEventArgs args)
+ {
+ var key = KeyInterop.KeyFromVirtualKey((int)args.KeyCode);
+ if (key.IsModifyKey())
+ {
+ this.pressedModifiers.Add(key);
+ }
+ else
+ {
+ this.Pressed?.Invoke(this, ShortcutKey.Create(key, this.pressedModifiers));
+ System.Diagnostics.Debug.WriteLine("KeyDown: " + this.pressedModifiers.Concat(EnumerableEx.Return(key)).JoinString(" + "));
+ }
+ }
+
+ private void InterceptorOnKeyUp(object sender, System.Windows.Forms.KeyEventArgs args)
+ {
+ if (this.pressedModifiers.Count == 0) return;
+
+ var key = KeyInterop.KeyFromVirtualKey((int)args.KeyCode);
+ if (key.IsModifyKey())
+ {
+ this.pressedModifiers.Remove(key);
+ }
+ }
+
+ }
+
+ public static class KeyHelper
+ {
+ public static bool IsModifyKey(this Key key)
+ {
+ // System.Windows.Forms.KeyEventArgs.Modifiers が LWin と RWin を含めてくれないので…
+ // あと Left と Right 区別できたらいいなって…
+ // _:(´ཀ`」 ∠):_
+
+ return key == Key.LeftAlt
+ || key == Key.LeftCtrl
+ || key == Key.LeftShift
+ || key == Key.LWin
+ || key == Key.RightAlt
+ || key == Key.RightCtrl
+ || key == Key.RightShift
+ || key == Key.RWin;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 54f501f

Please sign in to comment.