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

Help w/Undesired CTRL+N, CTRL+S side-effects 2

Status
Not open for further replies.

tamayok

Programmer
Sep 4, 2001
99
PR
Hi,

I have a form on an VFP 9.0-based application that needs to allow for fast data-entry. Users will use the mouse sporadically since almost all of the interactive activity will be keyboard-based.

I am having problems handling certain keyboard combinations.

I am not using any ON KEY LABEL assignments and there are no declared/active keyshortcuts in the (FILE) main menu.

The form's KeyPreview property is set to .T. and the KeyPress method contains this code:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
DO CASE
	CASE nKeyCode= 14	&& Key=CTRL+N
		IF THISFORM.IsEditing = 0 .AND. THISFORM.Cmd_New.Enabled = .T.
			THISFORM.Cmd_New.Click()
		ENDIF

	CASE nKeyCode= 19	&& Key=CTRL+S
		IF THISFORM.IsEditing <> 0 .AND. THISFORM.Cmd_Save.Enabled = .T.
			THISFORM.Cmd_Save.Click()
		ENDIF
ENDCASE

The CMD_New and Cmd_Save object's Click() events fire properly.

(a) However, the TextBox where the cursor was at the time of the key shortcut (CTRL+N) call also reflects the CTRL+N combination in the form of ASCII character 14 ( '' ). How do I suppress that '' input/output? I tried issuing CLEAR TYPEAHEAD on different locations but didn't succeed.

(b) After the CMD_Save.Click() event has fired, the CTRL+S key behaves becomes like a LEFT-ARROW in that it moves the cursor/focus to the preceeding TextBox (the LEFT-ARROW key also equals KeyCode 19 as per the INKEY() documentation). How do I prevent the cursor from moving to the preceeding TextBox Object and only execute the CMD_Save.Click() method?

I imagine the answer to both 'behavior problems' is the same, but after 2 1/2 hours invested in futile attempts I look forward to your collective wisdom!!!

Many many thanks,

Kenneth Tamayo
San Juan, Puerto Rico - USA
 
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
DO CASE
    CASE nKeyCode= 14 AND  nShiftAltCtrl== 2  && Key=CTRL+N
        IF THISFORM.IsEditing = 0 .AND.;
            THISFORM.Cmd_New.Enabled = .T.
            NODEFAULT
            THISFORM.Cmd_New.Click()
        ENDIF

    CASE nKeyCode= 19  AND  nShiftAltCtrl== 2
         && Key=CTRL+S
        IF THISFORM.IsEditing <> 0 .AND. ;
           THISFORM.Cmd_Save.Enabled = .T.
            NODEFAULT
            THISFORM.Cmd_Save.Click()

        ENDIF
ENDCASE
But this couldn't help with TextBox shortcut. Change either Shortcut either New record combination.

Borislav Borissov
 
Thanks Borislav,

I had forgotten about the NODEFAULT command and the help file didn't reference it under the "SEE ALSO" options of INKEY() and others I had looked at.

I added this code after the CASE statement:

Code:
IF INLIST(nKeyCode,14,19)
	NODEFAULT
ENDIF

and it seems to be working as intended.... MANY THANKS and ANOTHER STAR FOR YOU!!

Kenneth Tamayo
 
You must check if the CTRL is pressed also, if not the LEFT arrow will not works./

Borislav Borissov
 
Although you didn't ask about this, I just want to point out that rather than calling the Click method of a button, it's better to put the code in a form method and have both KeyPress and the button call that method. Doing so puts the code where it belongs (surely adding is a form operation) and makes the KeyPress code more readable.

In fact, I would have the Add and Save methods in the form class, so that every data entry form has them available.

Tamar
 
Thanks Borislav,

You are right, I had to include the condition (nShiftAltCtrl== 2) to allow for LEFT_Arrow movements.

Thanks Tamar,

I will apply your suggestion... Lends itself to many other efficiencies... In reality, all I am doing at the Cmd Button is calling such methods (ie: THISFORM.UserAdds(), THISFORM.UserUndo, etc..)

Also, it was great meeting you at the recent SouthWest Conference and now also enjoying the book you co-authored, "What's New in Nine".

Kenneth Tamayo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top