FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Bugs
   Software Bugs
(Moderator: fry)
   Passing RIGHT and LEFT
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Passing RIGHT and LEFT  (Read 447 times)
skloopy

WWW
Passing RIGHT and LEFT
« on: Dec 5th, 2003, 5:48am »

I'm writing a simple typewriter class, and i want to be able to pass the RIGHT and LEFT keys to it so I can change the cursor postion, but as soon as I pass the "key" variable RIGHT and LEFT don't work anymore..
 
Anybody know what i'm doing wrong?
 
Code:
class Typewriter
{
  String buffer = "";
  int insert = 0;
 
  Typewriter() {}
 
  void type(int c)
  {
    switch(c){
 case 8: delete(); break;
 //case RIGHT: if(insert > 0) insert--; break;
 //case LEFT: if(insert < buffer.length()) insert++; break;
 case 13:  // Avoid special keys
 case 65535:
 case 127:
 case 27:
 break;
 default: buffer = buffer+(char)c; break;
    }
  }
 
  void type(String s)
  {
    buffer = buffer+s;
  }
 
  void delete()
  {
    if(buffer.length() > 0) {
 buffer = buffer.substring(0,buffer.length()-1);
    }
  }
}

Thanks!
 
Andreas
Guest
Email
Re: Passing RIGHT and LEFT
« Reply #1 on: Dec 5th, 2003, 10:26am »

You have the Variable c as an int. You switch c. So c can't never be RIGTH or LEFT cause it's an int.
 
skloopy

WWW
Re: Passing RIGHT and LEFT
« Reply #2 on: Dec 5th, 2003, 8:11pm »

So are RIGHT and LEFT constants for chars then? If they're chars shouldn't they be castable to ints?
 
Sorry if this is obvious
« Last Edit: Dec 5th, 2003, 8:15pm by skloopy »  
benelek

35160983516098 WWW Email
Re: Passing RIGHT and LEFT
« Reply #3 on: Dec 6th, 2003, 12:28am »

Fry's post in this thread should help:
http://proce55ing.net/discourse/yabb/board_Syntax_action_displa_y_num_1051285219.html
 
skloopy

WWW
Re: Passing RIGHT and LEFT
« Reply #4 on: Dec 8th, 2003, 11:40pm »

Okay. i figured it out. It turns out that RIGHT and LEFT and all will work fine if you're using keyPressed, but I was using keyTyped, since it's a typewriter. I guess they just don't register in keyTyped..
 
Fry, is that intentional?
 
fry


WWW
Re: Passing RIGHT and LEFT
« Reply #5 on: Dec 9th, 2003, 7:53pm »

yeah, seems that sun handles the key codes differently for when it's keyTyped or keyPressed, so i need to modify things to work around that.  
 
so, i'll move this over to bugs. should be an easy fix.
 
Pages: 1 

« Previous topic | Next topic »