Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while trapping the navigation keys

 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java gurus,
I want to ask a question thet
Is there any way to make a generic program for trapping the navigation keys which can work on all mobile.
Actually when we work on games in j2me in that we have to move towards left,right,top and bottom and for that generally we trap the number keys 4,6,2 and 8 respectively why this?
why we can't trap the navigation keys here. and if we can trap these then whether we should these keys on the basis of keyCode parameter in keyPressed method of Canvas class or there is some other ways to do the same.

Rishi
 
Michael Kroll
Author
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I think the main problem, why the keys "2", "4", "6", and "8" are supported for navigation in games is, that application developers want to support most of the devices which are currently available at the market. What if a phone is not equpped with navigation keys? In this case you are not able to play the game an you will delete it. So the best way would be to support the navigation keys and the above mentioned numeric keys for navigation as well.
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Michal for the response,
But the main problem is still same.
I was asking which is most appropriate method to trap the navigation keys which will work in most of the mobile phones.
See as a matter of fact every mobile company gives the navigation keys in their models but in different ways.
Now i want to ask is there any fix standard to make the navigation keys as in the case of number keys. I mean to say that suppose num_key_1 is pressed then in keyPressed method of the canvas we can trap this key by its keyCode that is 49.
but in case of navigation keys is this the right way to check the navigation key by its keyCode number or there is some other way to identify that a particular navigation key has been pressed irrespective of the mobile make or the mobidel.
Thanks again for your reply and looking forward for the reply again..
Regards,
Rishi
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry "mobidel" is typing mistake in above posting
it is for "mobile model"
Rishi
 
Stefan Haustein
Author
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rishi Tyagi:
Hi Java gurus,
(...)
Actually when we work on games in j2me in that we have to move towards left,right,top and bottom and for that generally we trap the number keys 4,6,2 and 8 respectively why this?
why we can't trap the navigation keys here. and if we can trap these then whether we should these keys on the basis of keyCode parameter in keyPressed method of Canvas class or there is some other ways to do the same.

Hi Risji,
the Canvas class contains the method getGameCode() for this purpose. Using this method, you can convert the code provided by keyPressed() to one of the constants Canvas.UP, Canvas.DOWN, Canvas.LEFT, Canvas.FIRE etc. The mapping performed by getGameCode is device dependent, so on telephones without separate cursor keys, the corresponding numbers will be mapped to these constants, whereas on phones providing separate cursor keys these keys will be mapped to the game code constants...
The example canvas below shows how to control a little black square with the device cursor keys:

HTH,
Stefan
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan,
Although i was using the same means getGameCode() method but was not confirm about whether the Game action value returned by this method is reliable or not.
Thanks again to all java guru's who had given their time on my posting.
With best regards,
Rishi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic