473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

using timers for repeating characters

programming newbie. I'm work on a program that post characters into foreground application. everything is working nicely except for repeating characters. I thought using a task timer was the way to go but it seems that as the JVM cleans its garbage the time tries to catchup therefore posting more cycles in it preset duty cycle.

any hints on using java to control repeating characters or tasks?
Aug 23 '07 #1
11 2347
Nepomuk
3,112 Expert 2GB
Hi mauiboy! Welcome to TSDN!
I'm work on a program that post characters into foreground application.
Do you mean, that you send single characters to a different part of your program or a completely different application? Then the receiver should print the received character?
everything is working nicely except for repeating characters.
So, it works fine with, say {'n','i','c','e'} but not with {'b','e','t','t','e','r'}? (As there are 2 equal characters in a row.) Or do you mean, that sending just one character is fine, but when you send more than one, it goes wrong?
Aug 24 '07 #2
Yes just as you described: {'b','e','t','t','e','r'} i'm having a hard time controlling my repeat timer when I need to post a SINGLE character ex: {'b','e','t','t','e','r','r'} . the code looks something like this:

protected void repeatTimer()
{
repeatTimer = new Timer();
updateTask = new TimerTask()
{
public void run()
{
if ( mRepeatEnabled != false )
{
// Perform repeat the task
}
}
};
repeatTimer.schedule(updateTask, 1000, 100);
}

it works repeating characters but randomly post double and sometimes triple repeating characters when I only want single character post.

I tried Starting the timer when i need it & Stopping it when i don't but I ran into the problem of too many threads running error.

I also tried 2 timers, one for delaying the second timer. It worked better but still random double characters are posted.

maybe I shouldn't be using task timers and must try using wait() and invokelater().

any ideas?
Aug 24 '07 #3
JosAH
11,448 Expert 8TB
any ideas?
Nope, sorry; I understand zilch from what you described. What is so unique
about repeating (sic) characters? And what do you want to do with them that
makes them so different from unique characters? Care to elaborate?

kind regards,

Jos
Aug 24 '07 #4
sorry... i guess newbie is an overstatement.

so from the start I got this gift from a friend. a keyboard and i'm trying to make it work with my pda. The manufacture does not have a driver for my PDA so i started out on this grand idea of making one myself... Like i said its working I can type and post single keyboard character into my pda applications.

The problem i'm facing is adding repeating keys.

at first i thought is was my single character posting code so I disabled the repeating code. This was not it. single character posting works 100% perfectly.

When i try to add the repeating keys to the mix i get double and sometimes triple posted keys when i only want to post single.

This is where controlling the task time comes in. I'm using the task timer for repeating keys.

should i not use a task timer for this purpose?

does this help?
Aug 24 '07 #5
I think i figured out a way to control my time problem. learned that mytimer.cancel() will cancel mytimer and will not run anymore.

however, setting mytimer = null; will allow me to reschedule mytime for use again.

i've tested starting/stopping mytimer in the simulator without any crashes. My thinking is that by starting and stopping mytimer, i would know that the timer is always starting from time zero or whatever. its seems like a more controlled solution than toggling control variables.


public void controlRepeatTimer()
{
if ( yesRepeat != false)
{
if ( repeatTimer == null )
{
repeatTimer = new Timer();
repeatTimer();
}
else
{
repeatTimer.cancel();
repeatTimer = null;
}
}
}

protected void repeatTimer()
{
updateTask = new TimerTask()
{
public void run()
{
// Perform the repeat task
}
};
repeatTimer.schedule(updateTask, 1000, 100);
}

will try it in my application later to see if it really works.

wish me luck... :-)
Aug 24 '07 #6
JosAH
11,448 Expert 8TB
sorry... i guess newbie is an overstatement.

so from the start I got this gift from a friend. a keyboard and i'm trying to make it work with my pda. The manufacture does not have a driver for my PDA so i started out on this grand idea of making one myself...

[ ... ]

does this help?
Yep, at least now I understand the problem 'domain' (read: what your were talking
about ;-) So you have Java running on your PDA? That keyboard is connected
to that PDA through what type of port/slot/thingie? Does the keyboard cause an
event when a key is typed? And (just curious now) how does that Java application
send a keystroke to an application it knows nothing about?

kind regards,

Jos
Aug 24 '07 #7
Yep, at least now I understand the problem 'domain' (read: what your were talking
about ;-) So you have Java running on your PDA? That keyboard is connected
to that PDA through what type of port/slot/thingie? Does the keyboard cause an
event when a key is typed? And (just curious now) how does that Java application
send a keystroke to an application it knows nothing about?

kind regards,

Jos

I'm using this bluetooth keyboard the ones made of fabric with the key membrane in side it. the device I'm using is "java based has api that allows background applications to post events. I guess its just like programming language used for windows to post keyboard events into whatever application is running in the foreground.

Really i can't say much technically because i'm not really a programmer. just started learning because i like to diddle with things. I still have problems with the other parts of my application like connecting two bluetooth devices but its working for me cuz i know what and what not to do since i wrote the thing.
Aug 24 '07 #8
JosAH
11,448 Expert 8TB
I'm using this bluetooth keyboard the ones made of fabric with the key membrane in side it. the device I'm using is "java based has api that allows background applications to post events. I guess its just like programming language used for windows to post keyboard events into whatever application is running in the foreground.

Really i can't say much technically because i'm not really a programmer. just started learning because i like to diddle with things. I still have problems with the other parts of my application like connecting two bluetooth devices but its working for me cuz i know what and what not to do since i wrote the thing.
So you can register a 'Listener' to that device so that when it fires an event your
Listener wakes up and is able to do what it has to do? Or am I way off now?

kind regards,

Jos

ps. If I may ask so: what is the type/brand of that PDA?
Aug 24 '07 #9
So you can register a 'Listener' to that device so that when it fires an event your
Listener wakes up and is able to do what it has to do? Or am I way off now?

kind regards,

Jos

ps. If I may ask so: what is the type/brand of that PDA?

Yes. my application is sitting waiting for data to be received. I'm using bluetooth for communications so I have a bluetooth.listener waiting for events in my case data to come in through the port. I take the data which is some key codes and process it. the codes is usually 2 bytes indicating a down/up key position. using this info i post an event to push the appropriate character to the screen.

kinda fun seeing something occur. :-)

I'm using a blackberry cell phone / pda. not sure if you familiar with them but it does emails, memo, and other stuff.
Aug 24 '07 #10
JosAH
11,448 Expert 8TB
Yes. my application is sitting waiting for data to be received. I'm using bluetooth for communications so I have a bluetooth.listener waiting for events in my case data to come in through the port. I take the data which is some key codes and process it. the codes is usually 2 bytes indicating a down/up key position. using this info i post an event to push the appropriate character to the screen.

kinda fun seeing something occur. :-)

I'm using a blackberry cell phone / pda. not sure if you familiar with them but it does emails, memo, and other stuff.
What happens when you press a key on that keyboard and hold it? Will there be
a rapid stream of events or just one event or a slow repeating stream of events?

kind regards,

Jos
Aug 25 '07 #11
What happens when you press a key on that keyboard and hold it? Will there be
a rapid stream of events or just one event or a slow repeating stream of events?

kind regards,

Jos

got it working nicely using the last method i discussed. it works like any other keyboard repeating. there is a delay when the timer is started. this provides some time before the repeating starts so that the timer can be canceled if the key is not held down. after the initial startup delay the timer rate kicks in and begins to send repeat commands at the rate programmed.

When you hold the key down on the keyboard there is no rapid data stream just the data for the key being pressed or released.

I use the timer to simulate repeating and it seems to work nicely.
Spent most of the weekend rewriting most of the keyboard decoding code to make it better. taking some time becuse i don't know if my methods of programming is currect.

more later....
Aug 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
2
by: Al | last post by:
I'm currently attempting to use PLink (the console component of PUTTY - see http://www.chiark.greenend.org.uk/~sgtatham/putty/) as a Telnet component as I may in future need to change to using SSH...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.