Re: Tracking key combination
From: FISH (joeking_at_merseymail.com)
Date: 01/13/04
- Next message: Murat Tasan: "Re: obtaining a reference to the calling object"
- Previous message: Damien Legrand: "jpcap"
- In reply to: Kristian: "Tracking key combination"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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- ><>
- Next message: Murat Tasan: "Re: obtaining a reference to the calling object"
- Previous message: Damien Legrand: "jpcap"
- In reply to: Kristian: "Tracking key combination"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|