Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reliably detecting keystrokes
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Reliably detecting keystrokes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows Server 2003
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01105675
Message ID:
01105675
Vues:
99
I'm hoping somebody has some ideas, because I've run out of 'em <g>...

I have an application (Help Builder actually) that needs to capture keyboard input to override stock FoxPro behavior. Specifically I have an editbox that takes over Ctrl-Z and Ctrl-R handling for Undo and Redo because the VFP editbox undo buffer is very limited - basically as soon as the value is updated in any way via code (such as selstate updates or re-writing a value) the undo buffer is gone.

Long story short I use KeyPress to capture these keys and then handle them.

Now there are a number of problems. For one the keycodes for the Ctrl-Z and Ctrl-R overlap with Ctrl-Left and Ctrl-PgDn, so using KeyPress isn't going to help. The nShiftAltCtrl value also doesn't help because the overlap returns the same values since both key combinations use the Ctrl Keys. Smart mapping that <g>...

Anyway I've been using the GetKeyState API to get additional key information about the key pressed, and it works OK in most situations. The problem is that I have a few customers for whom this code just doesn't work as GetKeyState apparently doesn't return the right values.

I've included the code below. Has anybody run into this sort of thing before? Any idea why on some machines/keyboards this wouldn't work? And anybody have any idea how to reliably detect the key codes?


Here's the code:
* KeyPress
LPARAMETERS nKeyCode, nShiftAltCtrl


*** Don't want ESC to wipe out content of field.
IF nKeyCode = 27
  *** Eat the key
  NODEFAULT
ENDIF

*** Ctrl-Z
IF THIS.lUndoTracking 
   #DEFINE VK_LEFT 0x25
   #DEFINE VK_PGUP 0x21

   IF nKeyCode = 26
      *** Must check for Ctrl-Left which is also 26
      DECLARE INTEGER GetKeyState IN WIN32API INTEGER
      lnKeyState = GetKeyState(VK_LEFT)
      IF lnKeyState > -1 && only if left key is not pressed
         THIS.Undo()
         NODEFAULT
      ENDIF
   ENDIF

   *** Redo
   IF nKeyCode = 18
      *** Must check for PageUp which is also 26
      DECLARE INTEGER GetKeyState IN WIN32API INTEGER
      lnKeyState = GetKeyState(VK_PGUP)
      IF  lnKeyState > -1
         THIS.Redo() 
         NODEFAULT
      ENDIF
   ENDIF
ENDIF 
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform