блакбазык
блакбазык
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
Now, how I can call a function when the hotkey is being pressed ?
13 replies
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
Ok, it seem that I can put it as soon as I have a the windows Handle, so I put it here:
public Form1()
{
InitializeComponent();
Resize += Form1_Resize;
Load += Form1_Load;
HOTKEY_ACTIVE += Start;
FormClosing += Form1_FormClosing;


Api.RegisterHotKey(Handle, 1, HotKey.FsModifiers.None, Keys.Tab);
}
public Form1()
{
InitializeComponent();
Resize += Form1_Resize;
Load += Form1_Load;
HOTKEY_ACTIVE += Start;
FormClosing += Form1_FormClosing;


Api.RegisterHotKey(Handle, 1, HotKey.FsModifiers.None, Keys.Tab);
}
13 replies
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
Where should I use the RegisterHotKey(Handle, 1, HotKey.FsModifiers.None, Keys.Tab); ? Should I just put it directly in the main ?
13 replies
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
@LLVM Do I have to import user32.dll to use the hotkeys ?
13 replies
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
I have some override to detect the tabkey:
void Form1_KeyDown(object sender, KeyEventArgs e)
{


MessageBox.Show(e.KeyCode.ToString());
if (e.KeyCode == Keys.Tab)
{

MessageBox.Show("OH!");
}

}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Tab)
{
object sender = Control.FromHandle(msg.HWnd);
KeyEventArgs e = new KeyEventArgs(keyData);
Form1_KeyDown(sender, e);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{


MessageBox.Show(e.KeyCode.ToString());
if (e.KeyCode == Keys.Tab)
{

MessageBox.Show("OH!");
}

}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Tab)
{
object sender = Control.FromHandle(msg.HWnd);
KeyEventArgs e = new KeyEventArgs(keyData);
Form1_KeyDown(sender, e);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
13 replies
CC#
Created by блакбазык on 5/14/2023 in #help
❔ WinForm - Trigger a function when the program does not have focus when the user press TAB
Oh
13 replies