humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

send_key_up

send_key_up($key,$is_key); - данная функция используется для эмуляции отжатия заданной клавиши на клавиатуре на уровне событий, относительно текущего окна (фокус ввода передается текущему окну при вызове этой функции) (доступна с 4.6.37)

Функция на вход принимает параметры:

  • $key – клавиша, которая будет отжата.

    После отработки функция возвращает результат своей работы в скрипт :
  • true – эмуляция была сделана
  • false – эмуляция не была успешной

    Пример использования
    <?php
    $xhe_host = "localhost:7010";
    // Path to the init.php file for connecting to the XHE API
    $path = "../../../Templates/init.php";
    // Including init.php grants access to all classes and functionality for working with the XHE API
    require($path);
    
    // Scenario: Set text in navigation by first letter using send_key_up
    
    // Step: Get the main window interface
    $windowText = "localhost";
    $visibly = false;
    $mainWindow = WINDOW::$window->get_by_text($windowText, $visibly);
    
    // Step: Get the navigation input field through child elements
    $childNumber1 = 0;
    $toolbarClass = "XTPToolBar";
    $richEditClass = "RichEdit";
    $navigate = $mainWindow->get_child_by_number($childNumber1)
                                   ->get_child_by_class($toolbarClass)
                                   ->get_child_by_class($richEditClass);
    
    // Example 1: Set text in navigation by first letter using send_key_up
    echo "Example 1: Set text in navigation by first letter using send_key_up\n";
    
    // Step: Define key codes and parameters
    $yKeyCode = 89;
    $yIsAlt = 1;
    $aKeyCode = 65;
    $aIsAlt = 1;
    
    // Step: Send key up events
    $sendKeyUpResult1 = $navigate->send_key_up($yKeyCode, $yIsAlt);
    if ($sendKeyUpResult1) {
        echo "Y key up event sent successfully\n";
    } else {
        echo "Failed to send Y key up event\n";
    }
    
    $sendKeyUpResult2 = $navigate->send_key_up($aKeyCode, $aIsAlt);
    if ($sendKeyUpResult2) {
        echo "A key up event sent successfully\n";
    } else {
        echo "Failed to send A key up event\n";
    }
    sleep(2);
    
    // Example 2: Press Enter key to submit the navigation
    echo "Example 2: Press Enter key to submit the navigation\n";
    $enterKeyCode = 13;
    $keyResult = $navigate->key($enterKeyCode);
    if ($keyResult) {
        echo "Enter key pressed successfully\n";
    } else {
        echo "Failed to press Enter key\n";
    }
    sleep(1);
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7012"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>windowinterface.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Зададим текст в навигацию по первой букве : ")
    navigate=window.get_by_text("XWeb",false).get_child_by_number(0).get_child_by_class("XTPToolBar").get_child_by_class("RichEdit")
    echo(navigate.send_key_up(89,1)," ")
    echo(navigate.send_key_up(65,1)," ")
    sleep(2)
    echo(navigate.key(13),"<br>")
    sleep(1)
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #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 = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>windowinterface.send_key_up</font><hr>");
    				
    			// 1 шаг
    			echo("1. Зададим текст в навигацию по первой букве : ");
    			XHEWindowInterface navigate=window.get_by_text("XWeb",false).get_child_by_number(0).get_child_by_class("XTPToolBar").get_child_by_class("RichEdit");
    			echo(navigate.send_key_up("89",true)+" "+navigate.send_key_up("65",true)+" ");sleep(2);
    			echo(navigate.key(13)+"<br>");sleep(1);
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>keyboard.send_key_up</font><hr>");
    
    // 1 шаг
    echo("1. Зададим текст в навигацию по первой букве : ");
    navigate=window.get_by_text("XWeb",false).get_child_by_number(0).get_child_by_class("XTPToolBar").get_child_by_class("RichEdit");
    echo(navigate.send_key_up(89,1)+" "+navigate.send_key_up(65,1)+" ");browser.sleep(2);
    echo(navigate.key(13)+"<br>");browser.sleep(1);
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Window Interface    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .