Results 1 to 6 of 6

Thread: KeyDown not working

  1. #1
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default KeyDown not working

    Code:
    begin
      KeyDown(VK_1);
      wait(2000);
      KeyUp(VK_1);
    end.
    The above code outputs only a single '1' keystroke.

    Does anyone get multiple 1's from running this? (Just open Simba and run it, no SMART etc)

  2. #2
    Join Date
    Jan 2013
    Posts
    86
    Mentioned
    0 Post(s)
    Quoted
    25 Post(s)

    Default

    Nope only got a single 1, guess you'll have to do a repeat until for inputting multiple.

  3. #3
    Join Date
    Oct 2012
    Posts
    1,258
    Mentioned
    40 Post(s)
    Quoted
    588 Post(s)

    Default

    The key does seem to be down the whole time, but isn't currently spamming inputs like holding a key down on a normal keyboard would. It does however spam inputs if used on SMART.

  4. #4
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    I am not sure WHY it's acting like this, but this behavior is inherited from the functions in Windows: both SendInput and keybd_event acts this way. It's not a Simba specific "issue", any program using those windows functions will be forced to use a loop to repeat a key it seems.
    Last edited by slacky; 01-28-2017 at 11:51 PM.
    !No priv. messages please

  5. #5
    Join Date
    Dec 2011
    Posts
    193
    Mentioned
    5 Post(s)
    Quoted
    51 Post(s)

    Default

    Repeated keystrokes from holding a key down is a relationship between the OS and the keyboards controller. When we send keys through simba we are bypassing that controller. So we have to act on it's behalf.

    When a key is held, the default wait time before the key is classed as being "held" (rather than pressed slowly) is 500ms. Then the default Windows repeat is every 33ms (this can be changed in keyboard settings but it's very rare anyone has).

    So the following will simulate the default scenario of a key being held.

    Simba Code:
    KeyDown(VK_1);
    Wait(500);
    KeyUp(VK_1);

    for 1 to 9 do
    begin
      KeyDown(VK_1);
      KeyUp(VK_1);
      Wait(33);
    end;

    Now, I've never checked whether the wait occurs between the key up/down or after. For some reason I think it'd be done after, so that's what I've done above.

    The code above will repeat a key as though we wanted it inputted 10 times. Of course if you want the key held for a certain length of time, use a while loop on a timer. If this is for RS purposes, don't forget some random on that timer

    Edit:

    Another fun thing about this issue is that on RS the following
    Simba Code:
    KeyDown(VK_RIGHT);
    wait(2000);
    KeyUp(VK_RIGHT);
    will actually turn the camera for the time stated. This is because how the game handles camera inputs is different than how usual keyboard input is handled.

  6. #6
    Join Date
    Dec 2016
    Posts
    49
    Mentioned
    0 Post(s)
    Quoted
    22 Post(s)

    Default

    I actually just wrote something as I noticed this the other day as well while trying to write a script for FF2. I ended up with the following

    Simba Code:
    begin
      repeat
        if (exec) > 100 then
          break;
        inc(exec);
        sendKeys('x',1200,50); \\(presses 'x' 9 times)
        wait(200);
        sendKeys('y',800,50); \\ (presses 'y' 4-5 times)
        writeln((exec));
      until false;
    end;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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