Guess I should have noted that I used 2010 as the solution. If you just needed the code, I don't think I used anything that wouldn't be available in 3.5, maybe even 2.0. You'd just have to create your own solution and copy the code over file to file.
Global Hotkeys Register a hotkey that is triggered even when form isn't focused.
#17
Posted 23 May 2012 - 08:31 AM
Curtis Rutland, on 23 May 2012 - 07:39 AM, said:
Guess I should have noted that I used 2010 as the solution. If you just needed the code, I don't think I used anything that wouldn't be available in 3.5, maybe even 2.0. You'd just have to create your own solution and copy the code over file to file.
Yeah would have saved me some time though, but now your program works here and that's the most important thing
I'm more concerned if i'm able to implement your code into mine and get it to work. Let's see.
#18
Posted 23 May 2012 - 09:04 AM
It's as simple as I could make it. Check the test program for the implementation. The really important part is the WndProc method.
#19
Posted 23 May 2012 - 09:47 AM
#20
Posted 15 August 2012 - 06:52 AM
Hello,
Nice Tutorial!
But i have a problem. I downloaded your files (worked without a problem) and tried to make it work with multiple Hotkeys, just like reaper4334 explained it. But I always get an error at:
which sounds like that: "Windows32Exception was not handled"
If I put that "this.hwnd = form.Handle;" in a comment i get the same error at:
The whole code:
Global Hotkey.cs:
Form1.cs:
Im using Windows 7 64bit, .NET Framework 4.0 and Microsoft Visual C# 2010 Express.
What am i doing wrong?
Nice Tutorial!
But i have a problem. I downloaded your files (worked without a problem) and tried to make it work with multiple Hotkeys, just like reaper4334 explained it. But I always get an error at:
this.hWnd = form.Handle;
which sounds like that: "Windows32Exception was not handled"
If I put that "this.hwnd = form.Handle;" in a comment i get the same error at:
Application.Run(new Form1());
The whole code:
Global Hotkey.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace HotkeyWin
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Hotkeys;
namespace HotkeyWin
{
public partial class Form1 : Form
{
private Hotkeys.GlobalHotkey ghk;
public Form1()
{
InitializeComponent();
ghk = new Hotkeys.GlobalHotkey(Constants.NOMOD + Constants.NOMOD, Keys.F1, this);
}
//private void HandleHotkey()
//{
// WriteLine("Hotkey pressed!");
//}
//protected override void WndProc(ref Message m)
//{
// if (m.Msg == Hotkeys.Constants.WM_HOTKEY_MSG_ID)
// HandleHotkey();
// base.WndProc(ref m);
//}
private Keys GetKey(IntPtr LParam)
{
return (Keys)((LParam.ToInt32()) >> 16);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == Constants.WM_HOTKEY_MSG_ID)
{
switch (GetKey(m.LParam))
{
case Keys.F1:
WriteLine("Hotkey pressed!");
break;
}
base.WndProc(ref m);
}
}
private void Form1_Load(object sender, EventArgs e)
{
WriteLine("Trying to register SHIFT+ALT+O");
if (ghk.Register())
WriteLine("Hotkey registered.");
else
WriteLine("Hotkey failed to register");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!ghk.Unregiser())
MessageBox.Show("Hotkey failed to unregister!");
}
private void WriteLine(string text)
{
textBox1.Text += text + Environment.NewLine;
}
}
}
Im using Windows 7 64bit, .NET Framework 4.0 and Microsoft Visual C# 2010 Express.
What am i doing wrong?
This post has been edited by modi123_1: 15 August 2012 - 06:53 AM
Reason for edit:: fixed botched code tags
#21
Posted 15 August 2012 - 08:11 AM
Well, first I suggest going to my linked GitHub page and using the latest version of the library.
You can also see a more current example there:
https://github.com/c...s.Test/Form1.cs
You can also see a more current example there:
https://github.com/c...s.Test/Form1.cs
#22
Posted 25 August 2012 - 08:10 PM
It just very good article but I have that case
I need to fire some events with key enter
but when I do that the original function of key enter
is overridden and not works in other applications like in ms-word
or chatting.
is there way to do both
I need to fire some events with key enter
but when I do that the original function of key enter
is overridden and not works in other applications like in ms-word
or chatting.
is there way to do both
#23
Posted 26 August 2012 - 11:30 AM
I don't know, and I can't imagine a non-malicious use for hotkeying Enter.
|
|





MultiQuote



|