DVL Software Limited
[ About | Services | Products | Search | Feedback | Support ]

PowerBuilder Tips

Converting keycodes to character strings

Back to the Tips

With most objects, you can trap the key strokes using user events.  For example, on a datawindow object, you can create a user event using Event Id = pbm_dwnkey.  In this event, you'll find a parameter of type keycode.  This is a predefined enumerated data type with values such as KeyA!, KeyB!, etc.  But if you want to convert this value to a string, you'll find your choices are limited.

I searched for a method, but found none that did not involve a long extended CHOOSE statement.  It looks something like this:


      // for a..z, we convert to lower case at the end of the function.

      CASE keyA!

          ls_Key = 'A'

      CASE keyB!

          ls_Key = 'B'

      CASE keyC!

          ls_Key = 'C'

      CASE keyD!

          ls_Key = 'D'

      CASE keyE!

          ls_Key = 'E'

Just in case you need this, the source code is available here.

What use is it you ask?  Well, I used it on a datawindow to duplicate what you can do with an editable drop down datawindow.  For example, it was a list of parts.   If you pressed 'J', you went to the parts starting with 'J', etc.

Back to the Tips

[ About | Services | Products | Search | Feedback | Support ]

This page last updated: Tuesday, 29 February 2000
Copyright 1997, 1998, 1999, 2000 DVL Software Limited.  All rights reserved.