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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recognizing CTRL+INS in a Grid KeyPress Event 1

Status
Not open for further replies.

CBellucci

Programmer
Apr 20, 2007
38
US
I want to use CTRL+INS in a grid to insert a row in the grid. I can get CTRL+DELETE, CTRL+HOME, CTRL+END, CTRL+PGUP, CTRL+PGDWN to "kick" (that is, the KeyPress event recognizes them). But the CTRL+INS doesn't kick off the KeyPress event.

What am I doing wrong? Are there other options on the grid itself or elsewhere that may be muting this key combination?

Thanks in advance!
 
You're not doing anything wrong. Keypress simply doesn't trap CTRL+INS (that applies to all controls; it's not specific to the grid).

A couple of possible workarounds:

1. Get the user to hit CTRL + SHIFT + INS. That returns a key code of 146.

2. Use INKEY() instead (probably not a good solution, but I thought I'd mention it anyway.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Crap, why is it there is always a little "gotcha" when otherwise things would be so simple?

I don't like the three key solution (not consistent with anything else we use). What about using INKEY()?
 
Sorry, but it looks like INKEY() won't work either. I should have checked that before I suggested it.

Come to think of it, there's a good reason for that. CTRL + INS was the original Windows shortcut for "copy to clipboard" - an alternative to CTRL + C. It's probably rarely used for that anymore, but it's still a reserved combo: the price of backward compatibility.

Can you not find a different two-key combo?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Well, let's see what I've got:

Ctrl+PgUp goes to the top of the next column (inherited design)
Ctrl+Delete deletes current row
Ctrl+??? inserts new row at current position

I'm up for suggestions. Would like Ctrl+something (can change Ctrl+Delete if another pair of delete/insert makes sense).

Thanks for the help!
 
Well, in a Browse window, Ctrl+Y inserts a new row. But presumably your users won't know that, so it's not much help.

Maybe Ctrl + I? On the basis that I stands for "insert". But make sure that doesn't clash with inserting a Tab character (which is ASCII 9, which is Ctrl + I; but that's probably a red herring).

Or, maybe Shift + DEL to delete a row, and Shift + INS to insert a row?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yeah, I'll look at using Shift instead of Ctrl... Many thanks!
 
Come to think of it, there's a good reason for that. CTRL + INS was the original Windows shortcut for "copy to clipboard" - an alternative to CTRL + C. It's probably rarely used for that anymore, but it's still a reserved combo: the price of backward compatibility.

Yep. It's part of the old IBM CUA guideline. When Windows was "competing" with OS/2 it was implemented at a very low level in the Windows kernel. It's still there. Applications don't have to do anything to get the behavior. They have to actively prevent it if they don't want it.

It's more a part of the Windows bone marrow than the CTRL-C/etc. keystrokes they cribbed from the Mac.
 
CBellucci said:
Yeah, I'll look at using Shift instead of Ctrl... Many thanks!

You have chosen a simpler solution to that of using a macro.

The macro would need to call an in-scope object method or procedure which would need to check that the key combination had been pressed in the appropriate 'location' in the application.

Had CTRL+INS been pressed incorrectly, then you could either generate an error message or simply do nothing.

FAQ184-2483​
Chris [pc2]
PDFcommander.co.uk
motrac.co.uk
 
Shift+Ins doesn't kick either. I'm going back to using Ctrl+Home and wait for the inevitable "Why didn't you use Ctrl+Ins for Insert?" questions.
 
You can override any key combo, if you like, with ON KEY LABEL. While that's nothing I would really recommend, you can do for example: ON KEY LABEL CTRL+INS ? "insert"

The downside: This is not scoped to just a control, it would act for your whole application, the code you define for the key combo will run on it'sown, like ON ERROR, so the only halfways good concept would be to make use of _Screen.activeform.activecontrol, but that can also be .NULL., so you have to catch that.

In the grid.when you could do ON KEY LABEL CTRL+INS APPEND BLANK IN aliasname and in the lostfocus put ON KEY LABEL CTRL+INS, to undefine that combo. This way it's halfways scoped to the grid control.

Bye, Olaf.
 
Mike: Nope, still not getting Shift+Ins to kick.

Olaf: Thanks, I thought about doing that, but before the table automatically gets updated, I want to check to see if any records will "drop out" (there is a fixed amount of records that can be in the table) and warn the user. I suppose I could set a flag on GotFocus and reset everything on LostFocus, but once the user gets comfortable with using Ctrl+Ins, I'd have to repeat that over different forms. Just not sure I want to invest that much at this moment. I'd rather get the user familiar with a key combo that doesn't take the extra effort.
 
You can override any key combo, if you like, with ON KEY LABEL. While that's nothing I would really recommend, you can do for example: ON KEY LABEL CTRL+INS ? "insert"

Are you sure, Olaf? My point is that CTRL+INS is handled directly by Windows, and never reaches the application.

So it is never trapped by Keypress or INKEY(). You can't use it with ON KEY LABEL. And you can't assign a macro to it.

I was wondering if you could suggest a way to solve the problem with a Windows API call?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I simply tried ON KEY LABEL CTRL+INS ? "insert", and it prints "insert" on my _screen, any time I press CTRL+INS. I'm on Vista, maybe it's depending on the OS.

I'm pretty sure it works for CTRL+S, because that's how I once fooled myself and wasn't able to save changes to code while debugging. There is no such protection of system key combos.

You could try to BINDEVENT to Windows Message WM_KEYDOWN, that would be very low level.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top