Welcome to iPadForums.net Guest - Click Here to Register

how does the ipad handle keystroke events at the document level

This is a discussion on how does the ipad handle keystroke events at the document level within the iPad General Discussions forums, part of the Apple iPad Discussions category; I am working on a web application for my company that uses an iPad and a bluetooth barcode scanner as portable input devices. At first, ...

iPadForums.net is the original Apple iPad Forum! Registered Users do not see these ads. Please Register - It's Free!
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    iPad Noob!
    Member #
    6585
    Join Date
    Jun 2010
    Posts
    3

    Question how does the ipad handle keystroke events at the document level

    I am working on a web application for my company that uses an iPad and a bluetooth barcode scanner as portable input devices. At first, I used an input field to capture the scanners output and submit the form. The problem is, once the screen reloads, there is no way to get the input field to get focus. This results in the user having to tap the field before each scan or the input is ignored. I have tried several methods of focusing on the field when the page loads, but it seems that the javascript 'focus()' method simply will not work without user input such as tapping a button.

    So that was a dead end...then I tried to tie an event listener to the document object with document.addEventListener('keydown', doit, false) (which works just fine on the full version of safari). Again, the ipad ignores the input until I tap on a form field. Any Ideas?

  2. Ads


  3. #2
    iPad Noob!
    Member #
    8632
    Join Date
    Jul 2010
    Location
    L.A.
    Posts
    1
    I am having the exact same issue, and I was just about to begin playing with code to fix it.

    Which methods did you try without any luck?

    I was planning on a very simple:

    <body onload="document.formName.elements[X].focus();">

    (where X is the field # I want to begin with)

    Did you try something along these lines and it failed to work? I would have though this would be just fine.

  4. #3
    iPad Fan!
    Member #
    8435
    Join Date
    Jun 2010
    Location
    Gothenburg, Sweden
    Posts
    29
    Could something like this work?

    HTML:
    Code:
    <body onload="tigerFunc()">
    
    ...
    
    <input type="text" id="monkeyForm" />
    JavaScript (external file):
    Code:
    function tigerFunc()
    {
    document.getElementById('monkeyForm').focus();
    }
    Or have you already tried that?
    .
    When the birds start singing you should shut down your computer and go to bed.

    Sweden

    Jailbroken 32GB iPad Wi-Fi + 3G

  5. #4
    iPad Noob!
    Member #
    6585
    Join Date
    Jun 2010
    Posts
    3
    Yes, I have tried that as well. It seems that triggering a focus event on a form field with page load by direct means or by execution of a function does not work. However, if you tie the same function to a touch event or button press, focus works. I have a gut feeling that apple has deliberately done this to prevent the keyboard from appearing on page load.
    I have even gone as far as trying to capture keystrokes instead of using a text field. These methods will not work until you press something on the screen to give some element focus. I tried tying event listeners to the document and window objects, alas, no luck.

    I have tested all of these methods in safari on my Mac Mini and all have worked until i load the same page on the iPad.

    As I type this, I have another idea to try. The problem, in its simplest form, is the fact that no object has focus on page load. What if we don't submit the data with a traditional form submit? It might be possible to intercept the carrage return at the end of the string and use an AJAX call send the data and supply a callback function that inserts the return data into a div. This I have done before, but the trick here is clearing the content of the text field and maintain focus for the next scan. I will give it a shot an post my results back.

    Quote Originally Posted by mrgad View Post
    I am having the exact same issue, and I was just about to begin playing with code to fix it.

    Which methods did you try without any luck?

    I was planning on a very simple:

    <body onload="document.formName.elements[X].focus();">

    (where X is the field # I want to begin with)

    Did you try something along these lines and it failed to work? I would have though this would be just fine.

  6. #5
    iPad Noob!
    Member #
    6585
    Join Date
    Jun 2010
    Posts
    3

    got it

    here is the solution I came up with....


    Code:
    <?php
    if(isset($_REQUEST['data']))
    {
        $output=$_REQUEST['data'];
    }
    
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>test page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="../includes/js/jquery-1.4.2.min"></script>
        <script type="text/javascript">
            function testit(e)
            {
                var fdata=document.getElementById('data').value;
                $.post("ipadtest.php", $("#testform").serialize(), function(data){
                    $('#output').load("ipadtest.php?data="+fdata+" #output");
                });
                document.getElementById('data').value='';
                return false;
    
            }
        </script>
      </head>
      <body>
          <form name="testform" id="testform" onsubmit="return testit();">
            <input type="text" id="data" name="data" />
        </form>
          <div id="output"><?echo $output;?></div>
      </body>
    </html>
    This is a simple test using jquery libraries to accomplish a ajax request. because the text field never looses focus, you can scan several times without having to touch the screen. It just requires that you touch the text field when you are ready to begin scanning.


Home | Forum | Active Topics | What's New

Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Similar Threads

  1. Battery level indicator?
    By Checkpoint in forum iPad General Discussions
    Replies: 16
    Last Post: 08-02-2010, 06:11 PM
  2. multi level hierarchial tree style lists
    By omro in forum iPad Apps
    Replies: 0
    Last Post: 06-05-2010, 04:10 PM
  3. How do you name events with photos?
    By B0269h in forum iPad Help
    Replies: 0
    Last Post: 06-01-2010, 06:10 PM
  4. Replies: 2
    Last Post: 05-19-2010, 10:19 AM
  5. iPad Entry Level Point of Sales System For Food Services
    By Sonny Burnett in forum iPad General Discussions
    Replies: 1
    Last Post: 04-27-2010, 03:12 PM

Search tags for this page

handle keypress event in ipad

,
ios intercept keystrokes
,
ipad friendly javascript unload event
,

ipad input focus out

,

ipad javascript onload

,

ipad keypress event

,
ipad safari focus input text
,

ipad safari onkeydown

Click on a term to search for related topics.

Tags for this Thread