Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ctrl+Left-Arrow, Ctrl+Z: same key codes

Status
Not open for further replies.

Mike Lewis

Programmer
Joined
Jan 10, 2003
Messages
17,516
Location
Scotland
This is not really a question, but I was wondering if anyone else had noticed this: Ctrl+Left-Arrow and Ctrl+Z both have the same key codes.

If you trap those two keys in a Keypress event, you see that nKeyCode is 26, and nShiftAltCtrl is 2, in both cases. Similarly with INKEY() and LASTKEY().

In my own application, I use Ctrl+Z to let users undo a drag-and-drop operation. Today, a user pointed out that Ctrl-Left Arrow does the same thing, which is not what he wants.

I wonder if there's an easy workaround. Perhaps I can use low-level API calls to trap the keystrokes before they reach the app? But that could be a lot of hassle.

Or maybe I should just tell the users that it's a bonus feature?

Any comments would be welcome.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I can see where it could potentially be unwanted.
Say the user actually performs a drag/drop, then shortly after is editing some text and wants to skip back a word at a time. Would that still undo the drag/drop?

As for how to avoid interpret the keystrokes differently, I'm not sure. The IDE treats them differently though.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thanks for your reply, Dave.

I should have mentioned that the problem doesn't affect normal text editing. It's only happens because I explicitly trap key code 26 in a form's Keypress. So Ctrl+Left Arrow works OK in a textbox or edit box; it doesn't undo the drag-and-drop.

You're right that the IDE treats them differently. Interestingly, I can't trap Ctrl+Z when I'm running the app in the IDE, presumably because it's a reserved keystroke. But I can trap it OK when running from an EXE.

I've just asked the customer if they think this is a problem, and if they want me to find a solution. I'll wait and see what they say.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
There are keywords (no pun intended) you can search: scan code. I know Windows API could help, but can't tell you more from the top of my head without using google.

Another thing that surely can distinguis Ctrl+Z from Ctrl+Left arrow is ON KEY. While it introduces an interrupt working globally, you could forward the processing to a global object, eg formhandler, knowing if the form in question runs and should process that key stroke or not.

Besides that CTRL+Z is for Undo in general, like you use it, and CTRL+Y for repeating what you undid, both for stepping backward and forward in changes. Even in germany, where Z and Y keys are switched.

You might still want to use another hotkey combination to seperate the undo of drag&drop from other undo, as you get in conflict with automatic undo operations the editbox does support for example. That is when using ON KEY LABEL CTRL+Z you stop that from working.

Bye, Olaf.
 
Olaf,

Ah, yes. I hadn't thought of ON KEY (or ON KEY LABEL, perhaps). I normally avoid it, but I can see how it would work in this case.

I could set it up in the form's Activate, and kill it in the Deactivate. That way, it would only operate when the form in question was active. The command would set a property, which the Keypress can interrogate to tell it which key was pressed (assuming the Keypress would still fire; I'd have to experiment with that). Or, I could just have the ON KEY LABEL process the keystroke and not bother with the Keypress.

Fortunately, the form in question doesn't have any text editing controls, so I don't have to worry about intefering with the normal cursor keys or Ctrl+Z.

On your point about using another key for undoing the undo. My original plan was to have a Redo, which would do what you suggest.

But I abandoned it because it turned out to be so horribly complicated. Undo / Redo is something we take for granted in the software we use, but let me tell you, it's a pain to program it.

Just one example: If a user deletes an object, the Undo has to recreate it, including setting all its characteristics back to what they were before the deletion. And deleting an object is just one of around 20 actions which I have to allow to be undone. By the time I finished programming all that, I quietly forgot about doing the Redo.

Anyway, Olaf, thanks very much for your valuable input. I'll start experimenting with ON KEY and report back.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Late news: I just had an email from the client saying to leave things as they are. They will warn users that Ctrl+Left Arrow does an Undo, and to be careful not to press it unless it's what they want.

A nice easy solution for me, although it means I don't get to play with ON KEY LABEL. Never mind. They'll be another time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top