User Tools

Site Tools


Sidebar

en:objects:keyboard:send_events:send_key

send_key

send_key($key,$is_key=false,$ctrl=false,$alt=false,$shift=false); - this function is used to emulate keyboard input of a given key at the event level. It can work even if the program is minimized and in the system tray.

the input Function accepts parameters:

  • $key – the key that will be emulated. (string) Since version 4.9.17,the abbreviations VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT,VK_HOME,VK_END,VK_PAGEUP,VK_PAGEDOWN,VK_TAB,VK_ENTER,VK_SPACE, VK_ESC have BEEN added to emulate control keys
  • $is_key – if false, it interprets the key parameter as the key code and not the key itself key.
  • $ctrl – whether to combine the key with Ctrl. (available from version 4.9.17)
  • $alt – whether to combine the key with Alt. (available from version 4.9.17)
  • $shift – whether to combine the key with Shift. (available from version 4.9.17)

    If you press Ctrl while this function is running (or emulate pressing via the set_ctrl_prefix commands), the sent key will be interpreted as a set of hot keys for human.

    After testing, the function returns the result of its work to the script :
  • true – successfully emulated the input of the specified key(boolean)
  • false – operation failed (boolean)

    PHP example:

    <?php $xhe_host = "127.0.0.1:7013";
     
    $PHP_Use_Trought_Shell = false;
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> keyboard->".basename(__FILE__)."</font> <hr>";
     
    //1
    echo "1.Let's go to the polygon:";
    echo $browser->navigate("http://www.humanemulator.net/poligon/listbox.html")."<br>";
     
    //2
    echo "2.Set focus to listbox 4 and send the space bar:";
    echo $listbox->set_focus_by_number(4)."";
    echo $keyboard->send_key(VK_SPACE)." n";
    sleep(2);
     
    //3
    echo "3.Send key down:";
    echo $keyboard->send_key(VK_DOWN)." n";
    sleep(2);
     
    //4
    echo "4.Send key down:";
    echo $keyboard->send_key(VK_DOWN)." n";
    sleep(2);
     
    //five
    echo "5.Send the up key:";
    echo $keyboard->send_key(VK_UP)." n";
    sleep(2);
     
    //6
    echo "6.Send the page down key:";
    echo $keyboard->send_key(VK_PAGEDOWN)." n";
    sleep(2);
     
    //7
    echo "7.Send the page up key:";
    echo $keyboard->send_key(VK_PAGEUP)." n";
    sleep(2);
     
    //8
    echo "8.Send the end key:";
    echo $keyboard->send_key(VK_END)." n";
    sleep(2);
     
    //nine
    echo "9.Send home key:";
    echo $keyboard->send_key(VK_HOME)." n";
    sleep(2);
     
    //ten
    echo "10.Send tab key:";
    echo $keyboard->send_key(VK_TAB)." n";
     
    //end
    echo "<hr> <br>";
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1
    echo "1.Let's go to Yandex:";
    echo $browser->navigate("http://ya.ru")."<br>";
     
    //2
    echo "2.Let's focus on the search string:";
    echo $input->set_focus_by_number(0)."<br>";
     
    //3
    echo "3.Enter the given text:";
    echo $keyboard->send_input("teststring")."<br>";
     
    sleep(2);
     
    //select what we copied
    $input->get_by_number(0)->send_mouse_click(10,10);
    $input->get_by_number(0)->send_mouse_double_click(10,10);
     
    //4
    echo "4.Cut the selected text into the buffer:";
    echo $keyboard->send_key("88", false, true)."<br>";
     
    //five
    echo "5.Get the text in the clipboard:";
    echo $clipboard->get_text()."<br>";
     
    //end
    echo "<hr> <br>";
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1
    echo "1.Let's go to the polygon:";
    echo $browser->navigate("http://www.humanemulator.net/poligon/anchor.html")."<br>";
     
    //2
    echo "2.Get the coordinates of the element that can be selected by double-clicking:";
    $x = $element->get_x_by_inner_text("Links in Frame", false);
    $y = $element->get_y_by_inner_text("Links in Frame", false);
    echo $x."x".$y."<br>";
     
    //3
    echo "3.Select the element:";
    echo $mouse->send_click($x, $y)."";
    echo $mouse->send_double_click($x, $y)."<br>";
     
    //4
    echo "4.Copy the selected text Ctrl + Insert(45):";
    echo $keyboard->send_key("45", false, true)." n";
     
    //five
    echo "5.Get the copied text:";
    echo $clipboard->get_text(true);
     
    //end
    echo "<hr> <br>";
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1
    echo "1.Let's put the text into the buffer:";
    echo $clipboard->put_text("seo")."<br>";
     
    //2
    echo "2.Let's go to Yandex:";
    echo $browser->navigate("http://ya.ru")."<br>";
     
    //3
    echo "3.Let's focus on the search string:";
    echo $input->set_focus_by_number(0)."<br>";
     
    //4
    echo "4.Paste the text from the buffer: Ctrl + v(86):";
    echo $keyboard->send_key("86", false, true)."<br>";
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> keyboard.xxxxxxxxx </font> <hr>")
     
    # 1
    echo("1.Let's go to the polygon:")
    echo(browser.navigate("http://www.humanemulator.net/poligon/listbox.html"), "<br>")
     
    # 2
    echo("2.Set focus to listbox 4 and send the spacebar:")
    echo(listbox.set_focus_by_number(4), "")
    echo(keyboard.send_key(VK_SPACE), "
    ")
    sleep(2)
     
    # 3
    echo("3.Send key down:")
    echo(keyboard.send_key(VK_DOWN), "
    ")
    sleep(2)
     
    # 4
    echo("4.Send key down:")
    echo(keyboard.send_key(VK_DOWN), "
    ")
    sleep(2)
     
    # five
    echo("5.Send up key:")
    echo(keyboard.send_key(VK_UP), "
    ")
    sleep(2)
     
    # 6
    echo("6.Send the page down key:")
    echo(keyboard.send_key(VK_PAGEDOWN), "
    ")
    sleep(2)
     
    # 7
    echo("7.Send the page up key:")
    echo(keyboard.send_key(VK_PAGEUP), "
    ")
    sleep(2)
     
    # 8
    echo("8.Send the end key:")
    echo(keyboard.send_key(VK_END), "
    ")
    sleep(2)
     
    # nine
    echo("9.Send home key:")
    echo(keyboard.send_key(VK_HOME), "
    ")
    sleep(2)
     
    # ten
    echo("10.Send the tab key:")
    echo(keyboard.send_key(VK_TAB), "
    ")
     
    # end
    echo("<hr> <br>")
     
    echo("################################# <br> <br>")
     
    # 1
    echo("1.Let's go to Yandex:")
    echo(browser.navigate("http://ya.ru"), "<br>")
     
    # 2
    echo("2.Set focus to search string:")
    echo(input.set_focus_by_number(0), "<br>")
     
    # 3
    echo("3.Enter the given text:")
    echo(keyboard.send_input("teststring"), "<br>")
     
    sleep(2)
     
    # select what you copied
    input.get_by_number(0) .send_mouse_click(10,10)
    input.get_by_number(0) .send_mouse_double_click(10,10)
     
    # 4
    echo("4.Cut the selected text into a buffer:")
    echo(keyboard.send_key("88", true, true), "<br>")
     
    # five
    echo("5.Get the text in the clipboard:")
    echo(clipboard.get_text(), "<br>")
     
    # end
    echo("<hr> <br>")
     
    echo("################################# <br> <br>")
     
    # 1
    echo("1.Let's go to the polygon:")
    echo(browser.navigate("http://www.humanemulator.net/poligon/anchor.html"), "<br>")
     
    # 2
    echo("2.Get the coordinates of the element that can be selected by double clicking:")
    x = element.get_x_by_inner_text("Links in Frame", false)
    y = element.get_y_by_inner_text("Links in Frame", false)
    echo(x, "x")
    echo(y, "<br>")
     
    # 3
    echo("3.Select the item:")
    echo(mouse.send_click(x, y), "")
    echo(mouse.send_double_click(x, y), "<br>")
     
    # 4
    echo("4.Copy the selected text Ctrl + Insert(45):")
    echo(keyboard.send_key("45", true, true), "
    ")
     
    # five
    echo("5.Get copied text:")
    echo(clipboard.get_text())
     
    # end
    echo("<hr> <br>")
     
    echo("################################# <br> <br>")
     
    # 1
    echo("1.Put the text in the buffer:")
    echo(clipboard.put_text("seo"), "<br>")
     
    # 2
    echo("2.Let's go to Yandex:")
    echo(browser.navigate("http://ya.ru"), "<br>")
     
    # 3
    echo("3.Let's focus on the search string:")
    echo(input.set_focus_by_number(0), "<br>")
     
    # 4
    echo("4.Paste the text from the buffer: Ctrl + v(86):")
    echo(keyboard.send_key("v", true, true), "<br>")
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    #endregion
     
     class Program: XHEScript
     {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7010";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> keyboard.send_key </font> <hr>");
     
    //1 step
    echo("1.Let's go to Yandex:");
    echo(browser.navigate("http://ya.ru") + "<br>");
     
    //step 2
    echo("2.Set focus to the search string:");
    echo(input.set_focus_by_number(0) + "<br>");
     
    //step 3
    echo("3.Let's search for SR(code 83 + 92 + 13):");
    keyboard.set_current_language("en");
    echo(keyboard.send_key("83") + "");
    echo(keyboard.send_key("82") + "");
    echo(keyboard.send_key("13", true));
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7010";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> keyboard.send_key </font> <hr>");
     
    //1 step
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("http://www.humanemulator.net/poligon/listbox.html") + "<br>");
     
    //step 2
    echo("2.Set focus to listbox 4 and send the space bar:");
    echo(listbox.set_focus_by_number(4) + "");
    echo(keyboard.send_key(VK_SPACE) + "
    ");
    browser.sleep(2);
     
    //step 3
    echo("3.Let's send the down key:");
    echo(keyboard.send_key(VK_DOWN) + "
    ");
    browser.sleep(2);
     
    //step 4
    echo("4.Send key down:");
    echo(keyboard.send_key(VK_DOWN) + "
    ");
    browser.sleep(2);
     
    //step 5
    echo("5.Send the up key:");
    echo(keyboard.send_key(VK_UP) + "
    ");
    browser.sleep(2);
     
    //6 step
    echo("6.Send the page down key:");
    echo(keyboard.send_key(VK_PAGEDOWN) + "
    ");
    browser.sleep(2);
     
    //step 7
    echo("7.Send the page up key:");
    echo(keyboard.send_key(VK_PAGEUP) + "
    ");
    browser.sleep(2);
     
    //step 8
    echo("8.Send the end key:");
    echo(keyboard.send_key(VK_END) + "
    ");
    browser.sleep(2);
     
    //step 9
    echo("9.Send home key:");
    echo(keyboard.send_key(VK_HOME) + "
    ");
    browser.sleep(2);
     
    //step 10
    echo("10.Let's send the tab key:");
    echo(keyboard.send_key(VK_TAB) + "
    ");
     
    //end
    echo("<hr> <br>");
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1 step
    echo("1.Let's go to Yandex:");
    echo(browser.navigate("http://ya.ru") + "<br>");
     
    //step 2
    echo("2.Set focus to the search string:");
    echo(input.set_focus_by_number(0) + "<br>");
     
    //step 3
    echo("3.Enter the given text:");
    echo(keyboard.send_input("teststring") + "<br>");
    browser.sleep(2);
     
    //select what we copied
    input.get_by_number(0) .send_mouse_click(10,10);
    input.get_by_number(0) .send_mouse_double_click(10,10);
     
    //step 4
    echo("4.Cut the selected text into a buffer:");
    echo(keyboard.send_key("88", true, true) + "<br>");
     
    //step 5
    echo("5.Get the text in the clipboard:");
    echo(clipboard.get_text() + "<br>");
     
    //end
    echo("<hr> <br>");
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1 step
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("http://www.humanemulator.net/poligon/anchor.html") + "<br>");
     
    //step 2
    echo("2.Get the coordinates of the element that can be selected by double-clicking:");
    x = element.get_x_by_inner_text("Links in Frame", false);
    y = element.get_y_by_inner_text("Links in Frame", false);
    echo("x =" + x + "y =" + y + "<br>");
     
    //step 3
    echo("3.Select the element:");
    echo(mouse.send_click(21,384) + "");
    echo(mouse.send_double_click(21,384) + "<br>");
     
    //step 4
    echo("5.Copy the selected text:");
    echo(keyboard.send_key("67", true, true) + "
    ");
     
    //step 5
    echo("5.Get the copied text:");
    echo(clipboard.get_text(true));
     
    //end
    echo("<hr> <br>");
     
    echo("//////////////////////////////////////////////////////////////////<br> ");
     
    //1 step
    echo("1.Let's put the text into the buffer:");
    echo(clipboard.put_text("seo") + "<br>");
     
    //step 2
    echo("2.Let's go to Yandex:");
    echo(browser.navigate("http://ya.ru") + "<br>");
     
    //step 3
    echo("3.Let's focus on the search string:");
    echo(input.set_focus_by_number(0) + "<br>");
     
    //step 4
    echo("4.Insert text from the buffer:");
    echo(keyboard.send_key("86", true, true) + "<br>");
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/keyboard/send_events/send_key.txt · Last modified: 2026/08/05 22:45 (external edit)