Created
February 24, 2018 22:37
-
-
Save RuiGuilherme/287ed0bba856feea876993db9b9573b1 to your computer and use it in GitHub Desktop.
vlw SirMester. :3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Windows; | |
using System.Windows.Input; | |
using System.Windows.Threading; | |
using WpfApp3; | |
namespace Model.Libraries.KeyBoardHooking | |
{ | |
public class KeyBoardHooking : Window | |
{ | |
[DllImport("User32.dll")] | |
private static extern short GetAsyncKeyState(Key vKey); | |
[DllImport("User32.dll")] | |
private static extern short GetAsyncKeyState(int vKey); | |
public KeyBoardHooking() | |
{ | |
Thread Thread = new Thread(() => | |
{ | |
while (true) | |
{ | |
// tecla abrir/fechar (PgUp) | |
if (GetAsyncKeyState(33) == -32767) | |
{ | |
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => | |
{ | |
if (Application.Current.MainWindow.Topmost == true) | |
{ | |
Application.Current.MainWindow.Hide(); | |
Application.Current.MainWindow.Topmost = false; | |
} | |
else | |
{ | |
Application.Current.MainWindow.Show(); | |
Application.Current.MainWindow.Topmost = true; | |
} | |
})); | |
} | |
Thread.Sleep(5); | |
} | |
}) | |
{ | |
IsBackground = true | |
}; | |
Thread.SetApartmentState(ApartmentState.STA); | |
Thread.Start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment