473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Creating a user definable hotkey (.NET1.1/VS2k3/WinForms)

Hi all,

I have some often-performed tasks in my applications that I want users
to be able to specify hotkeys for. However, I don't want to hard code
these hotkeys, as sooner or later some other app is bound to use the
same thing, causing end user frustration. So I want the end user to be
able to specify the hot key to use for task X in the configuration window.

Now receiving and handling the hotkey is no problem. I do that easily
enough trough the magic of the Win32 RegisterHotKey() function and
friends, and then overriding my WndProc handler checking for an m.Msg of
WM_HOTKEY (0x0312).

However, I also want the part of the application where the user defines
what hotkey to use to be friendly. There are of course several
approaches to this. One is the GUI one with a checkbox for Ctrl, Alt and
Shift (optionally the Win button), and then a dropdown with the keys.
However, I like the one that is in the start menu properties a lot
better, for many reasons. (To check it out, go to Start -> (All)
Programs -> Accessories, and right click Calculator, then choose
Properties). The procedure there is as simple as can be - activate the
"Shortcut key" field, press your hotkey, and voila - instant hotkey
definition.

I have struggled quite a bit with figuring out which is the correct way
to handle this. I've tried doing it via events on the textbox itself
(handling KeyPress, KeyDown, KeyUp and then reading ModifierKeys or just
the passed data), and I've tried to do it overriding the forms own
ProcessDialogKey. The latter seems to make me have to check against
every possible key that has been pressed, while the former makes me jump
trough a lot of loops to get what I want (require a modifier key, react
properly when keys are let go of in every possible order etc).

Thus I am turning to the experts; What way would you go about to handle
this? Or would you go in a completely different direction, possibly
meeting and getting to know new and interesting people along the way?

My requirements are simple; I want my users to easily specify the
hotkeys to use for a number of common operations. I want to require the
use of modifier keys (any number of modifiers higher than 0), as this
will be a system wide hotkey. And if possible (practical), I would
really like it if my users could use the Win key as a modifier in
additional to Ctrl/Alt/Shift. Also, since I have international users,
the solution should be open for any character that is not a modifier to
be used as "the" key).

If anyone could help shed some light on The Right Thing here, I would
highly appreciate it!

Thanks and best regards,

Rune Jacobsen
Jun 6 '06 #1
1 5932
Hi again,

Since my first post got no responses, I've been moving on to try to
figure this one out myself. I'm trying to use a combination of KeyDown
and ProcessDialogKey to read a users' wanted hotkey combination. The
reason I am doing it this way is that I want my users to have the option
of using the Windows key as a modifier in addition to Shift, Alt and Ctrl.

The strange thing, however, is that there seems to be a bug in my logic
when using ProcessDialogKey to get the modifiers pressed. The actual key
is handled in the KeyDown event, but I am using an override of
ProcessDialogKey for the window to set modifier flags so that I can
capture something precise when the user does his thing. What I am doing
in the override is to check the keyData for Keys.Control, Keys.Alt,
Keys.Shift and Keys.LWin. All the others work as expected, but LWin
seems to be always pressed. The simple way I check for this is something
along these lines:

if( (keyData & Keys.Control) != 0 )
modifiers |= Keys.Control;

etc. - but the LWin one always hits.

To test if this is me going mental or something else, I made a very
simple WinForm app in VS2003. One form only, added two textboxes to it,
and inserted the following code for the override:

protected override bool ProcessDialogKey(Keys keyData)
{
textBox1.Text = keyData.ToString();
if( (keyData & Keys.LWin) != 0 )
textBox2.Text = "LWin has been pressed!";
else
textBox2.Text = "";
return base.ProcessDialogKey (keyData);
}

As you will hopefully agree, textBox1 simply shows you which keys are
being pressed right now, while textBox2 should only contain text when
the left Windows key is pressed.

Well, try it. When I try it here (English WinXP Sp2, .NET1.1, VS2003),
the only key that DOESN'T cause LWin to seem pressed, is the space bar!
Every other key on the keyboard results in "LWin has been pressed!"
appearing in textBox2.

Could someone please explain this to me, as the size of the headache it
is causing is not proportional to the fun of trying to figure it out..

Thanks for any help!

Best regards,

Rune Jacobsen
Jun 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ray Lavelle | last post by:
I'm new to VB .NET. In the past when creating an application, if I had an input form I would just call the set and get methods on the object that mapped to my database table in order to store and...
0
by: Wayne Gibson | last post by:
Hi all, Please ignore the other post.. The cat jumped on the machine and sent it before I could stop it!! Was wondering if anybody has expericence this problem.. I am writting an application...
6
by: Anne Lynn | last post by:
I have a query where I defined three fields must match - Physician, Date of Service and Claim#. No problem. Now I need to add parameters that allow a user to define a 4th field= Procedure Codes. ...
0
by: Valentin Samko | last post by:
How can one create (or subclass) a WinForms control in managed c++ program? I can inherit from ListView and add all the functionality I need, but then there is no way to add my new control to...
0
by: J'son | last post by:
Guys, I need to build a web intranet application that can automatically create a user account when a new user registers on the site. The user account will be on the web server, member of the...
1
by: Bob Alston | last post by:
Anyone have experience in building Access apps with user definable fields? (Not the kind of fields where you just let the user define the label for a pre set number of predefined fields.) I...
2
by: Protoman | last post by:
How would I write a user defnable letter swapping algorithm? I've written an Enigma encrypting program, and I need to redo the plugboard function. Right now, the letter swapping is fixed. I need to...
1
by: brooksje | last post by:
I am looking for a good way to use password security and user level access control with an Access 2003 database. I got code that does a good job of creating a login procedure using a table of names,...
1
by: qwedster | last post by:
Hola! In the following code snippet, I am creating User Defined Function (T-SQL) programmatically into database from C# Code: BTW, this code originally I wrote for creating StoredProcedure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.