Re: Tracking key combination

From: FISH (joeking_at_merseymail.com)
Date: 01/13/04


Date: 13 Jan 2004 05:49:05 -0800

kristian@detandetfirma.dk (Kristian) wrote in message news:<c9e510f2.0401120724.41368093@posting.google.com>...
> How do I track a key combination like this '<abcd'?
> I have trapped the '<' key using keypressed in a jtextpanes
> keylistener. But what to do now? how do I trap the next lets say 3
> charactes typed by the user?

Create a char array, and store the characters in it using a counter which
indicates the next free index. To avoid having to resize or copy the
array, make the counter wrap around to the start of the array when it
exceeds the upper bounds: cnt=cnt%array.length; Then check the previous
n chars (remembering to wrap to the end if exceeding the lower bounds of
the array) for the required character sequence, where 'n' is the length
of the search string.

Suppose we are looking for the string ABCDE, and the user types xyABCDE:
(our array is the same size as the search string, which makes life easier)

----- Nothing typed.
^
xy--- User types xy, counter at [2].
  ^
xyABC User adds ABC, counter has wrapped to [0].
^
DEABC User adds DE, counter at [2]. Our required sequence is at
  ^ [2]-->[1] ( [2]-->[4], then [0]-->[1] ) which we can check
         by looping [2]-->[6] while %'ing so 5 and 6 wrap to 0 and 1.

Modifying this scheme to check for different strings of varying sizes
requires a little bit more work, but not much.

-FISH- ><>



Relevant Pages

  • Best approach?
    ... I've written a function that parses a search string and returns a 1D array ... search terms are entered. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Search through a (large) binary file.
    ... thing into a byte array and then just work off that byte array. ... chunks forces you to deal with the situation where the data you're ... A general purpose solution would involve some kind of list or circular buffer of blocks you've read, but if you can ensure that the length of the search string is always less than the size of a single read block, you could get away with a couple of variables or a two-element array. ... Just read data and at each byte offset, compare your search string to the bytes starting at that offset. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FileListBox
    ... Try Step -1 to go backwards through the list, collection, array, etc... ... the user specifies a search string to ... > find in the filenames along with the string to replace it with. ... > on this, I want to cycle through a FileListBox, looking at each ...
    (microsoft.public.vb.general.discussion)
  • Re: Best way to find if item is in array?
    ... > To ensure that your search string is not embedded try this: ... > This presumes that "|" is not a character in your array. ...
    (comp.lang.javascript)
  • Re: Find value in array
    ... Wonder how we adjust the formula to take care of A6 being blank or having an entry (e.g. business card) not found in the array. ... writing device pencil pen marker sharpie ... The way I want it to work, if a user types in 'pen', it returns the value ...
    (microsoft.public.excel.worksheet.functions)