Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Creating a basic key buffer  (Read 2401 times)
0 Members and 1 Guest are viewing this topic.
Offline Porlus

Junior Devvie

« Posted 2012-07-01 21:46:34 »

Hi all, I've made a really basic keyboard class that holds the states of each key, which are for me (pressed and not pressed). I've made the half of the class logs key presses and allows you to check whether a specific key is currently pressed. I'm just wondering how I would go about implementing a key buffer, so that I can allow the user to, for example, type characters and have the text be inserted somewhere within the program. Could anyone explain to me how this would typically be done? Any tutorials anyone has would be great too.

Thanks in advance,

Paul Smiley
Offline aazimon
« Reply #1 - Posted 2012-07-02 16:39:48 »

  I'm not fully understanding what you are trying to do. Are you want to set up a system that stores which keys are pressed and which ones are not, then the remaining program will access that system to determine if a particular key is pressed or not?
   If so, you will want to have your program "hook into" the key system, so that it can poll a key's state. For example, a sprite class would have a reference to the key system (or just the keys it's interested in), then it will query the reference for the key's current state. Similar to the ActionListeners in Swing.
Let me know if that's what you're looking for.
Aazimon Smiley
Offline pjt33

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

« Reply #2 - Posted 2012-07-02 21:37:10 »

As always, the answer is "It depends".

The two critical questions would be 1) where do you want to trade off between OO and to-the-metal. (java.util.List<Character> or a circular buffer?); 2) what do you want to do about key repeats?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #3 - Posted 2012-07-03 01:41:44 »

Where would the text be written? Either use a JOptionPane for input or create your own TextField GUI widget.

Offline Porlus

Junior Devvie

« Reply #4 - Posted 2012-07-03 01:50:40 »

Ah, I've worked out a way to do it. For anyone who's interested I just made an ArrayList of KeyEvents and added keys to it as they're pressed. Then I loop through this ArrayList and add them to whatever other part of the application, then at the end of that tick in the game loop I clear the ArrayList. Smiley
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (25 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (202 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!