New topic: 

Key Capture Help Needed

<http://forums.realsoftware.com/viewtopic.php?t=32403>

       Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic         Author  
Message       NA9D           Post subject: Key Capture Help NeededPosted: Mon 
Feb 08, 2010 3:12 pm                        
Joined: Mon Feb 01, 2010 3:36 pm
Posts: 22              Hey guys,

I've gotten to a point where I'm just plain stuck and need some help.

In my application, I want to have things so that a user can enter a sequence of 
numbers and by that entry set various controls.  I have an array of pop-up 
control.  The sequences I am trying to trap consist of 2 sets of numbers 
separated by a dash.  The numbers can be one digit or two digit.  So I'm trying 
to trap anywhere from 3 to 5 total keystrokes.  So for example:

1-1
10-1
2-12
15-13

Are all valid key sequences.  

The numbers before the dash is the index of the pop-up menu control.  The 
second set of numbers is the listindex inside the pop-up control.  Make sense?

Now, since the sequences can vary a bit, I figured that I would set up a timer 
of some sort so that if the user enters say 1-1, then the action to change the 
appropriate control will trigger once a pre-established delay time takes place 
(say 3 seconds).  Additionally, if a user presses just one or two keys (not 
valid combinations), then I want those values to be reset after the delay time 
as well.  

Since the keydown event is triggered and started from scratch every time a key 
is pressed, I am storing all my keypresses in global properties.  I also have a 
property called "strokecount" which is the number of key strokes - this is set 
initially to 0 in my open event for my main window.

So in my keydown event, I check to see if "key" is of the numbers 0 - 9 or "-" 
if it is, then I increment strokecount by one and then depending on the value 
of strokecount, I have a case statement that stores the "key" variable in the 
associated property.  These are named KeyPressed1 to KeyPressed5.

Once strokecount increments to 3 I then execute code to potentially send the 
command sequence to set the appropriate control.  This is where my problems 
come in.

I'm successfully able to capture and change any 3 sequence set of keystrokes.  
The problem is going beyond that to 4 or 5 key sets.  I can't figure out how to 
get a timer function to work while at the same time wait for trapping 
keystrokes. I've tried doing this inside the keydown event, by calling a 
separate method or even by changing the state of a hidden checkbox control and 
using the "action" event from that control to run the rest of the code figuring 
I could run the timer loop in that code while waiting for other keystrokes to 
be trapped.  But nothing is working properly and so I'm stuck.  

I'm not sure how well I've explained what I'm trying to do or what I've done 
here so if you need me to clarify anything please ask.  But the bottom line is 
that I'm wanting to trap and store up to 5 keystroke values within a certain 
period of time.  So perhaps to re-explain:

1.) A first keystroke is trapped, say number 1.  Now wait 3 seconds to see if 
another keystroke is trapped.  If yes then go to step two.  If not, clear all 
properties related to this and start the process over on the next keydown event.

2.) A second keystroke is trapped.  Wait 3 seconds to see if another keystroke 
is trapped.  If yes, then go to step three.  If not, clear all properties 
related to this and start the process over on the next keydown event.

3.) A third keystroke is trapped.  Wait 3 seconds to see if another keystroke 
is trapped.  If yes, go to step 4.  If no, then check to see that the sequence 
of keys entered in steps 1 to 3 are valid (ie: 1-1 and not 111 or -11, etc.).  
If sequence is valid, send the command to change the listindex (3rd digit) of 
the control (first digit) ie:

PopUpMenu(mainWindow.Source(Val(KeyPressed1)-1)).listindex = Val(KeyPressed3)-1

"Source" is the name of the Pop-Up control on the main window.


  After this, all values are then cleared and then we are ready to start the 
process over on the next keydown event.  If sequence is not valid, then clear 
all values and get ready to start over on next keydown event.

4.) A fourth keystroke is trapped.  Wait 3 seconds to see if another keystroke 
is trapped.  IF yes, go to step 5.  If no, check to see that the sequence of 
keys entered so far is valid.  If valid, then send the key values to the 
appropriate control similar to 3 above.  I don't think I need to repeat the 
code as it's very similar.  Once that command is executed, then re-initialize 
everything to get ready for the next set of keystrokes when they happen.  If 
the key sequence is not valid, don't send anything and just clear everything 
out and get ready for the next keydown events.

5.) A fifth keystroke is trapped.  No need to wait here as 5 is the maximum 
number of keys.  So then we check to see if the key sequence is valid.  If yes, 
we send the command and initialize for next time.  If no, we just initialize.

So that's how I want it to work.  The problem is that I can't get the 3 second 
wait and the watching for a keydown even to happen simultaneously.  Any help in 
how to do this would be much appreciated.  So for the long post! 

Thanks,

Jon   
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to