using timers for repeating characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mauiboy
    New Member
    • Aug 2007
    • 8

    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?
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi mauiboy! Welcome to TSDN!
    Originally posted by mauiboy
    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?
    Originally posted by mauiboy
    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?

    Comment

    • mauiboy
      New Member
      • Aug 2007
      • 8

      #3
      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.sch edule(updateTas k, 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?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by mauiboy
        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

        Comment

        • mauiboy
          New Member
          • Aug 2007
          • 8

          #5
          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?

          Comment

          • mauiboy
            New Member
            • Aug 2007
            • 8

            #6
            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 controlRepeatTi mer()
            {
            if ( yesRepeat != false)
            {
            if ( repeatTimer == null )
            {
            repeatTimer = new Timer();
            repeatTimer();
            }
            else
            {
            repeatTimer.can cel();
            repeatTimer = null;
            }
            }
            }

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

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

            wish me luck... :-)

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by mauiboy
              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

              Comment

              • mauiboy
                New Member
                • Aug 2007
                • 8

                #8
                Originally posted by JosAH
                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.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by mauiboy
                  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?

                  Comment

                  • mauiboy
                    New Member
                    • Aug 2007
                    • 8

                    #10
                    Originally posted by JosAH
                    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.liste ner 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.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by mauiboy
                      Yes. my application is sitting waiting for data to be received. I'm using bluetooth for communications so I have a bluetooth.liste ner 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

                      Comment

                      • mauiboy
                        New Member
                        • Aug 2007
                        • 8

                        #12
                        Originally posted by JosAH
                        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....

                        Comment

                        Working...