using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public partial class MainForm : Form
private int ALT = 0x0001;
private Keys key = Keys.PrintScreen;
private bool canWork = true;
Timer timer = new Timer();
timer.Tick += Timer_Tick;
private void Timer_Tick(object sender, EventArgs e)
private void MainForm_Load(object sender, EventArgs e)
this.FormClosing += ClearHotKey;
RegisterHotKey(this.Handle, uniqId, (uint)ALT, (uint)key);
private void ClearHotKey(object sender, CancelEventArgs e)
UnregisterHotKey(this.Handle, uniqId);
[DllImport("user32.dll")]
bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32.dll")]
bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message keyPressed)
if (keyPressed.Msg == 0x0312)
switch (keyPressed.WParam.ToInt32())
case 1: SetPrtSc(); break;
base.WndProc(ref keyPressed);