Files
php-doc-ru/reference/misc/functions/sapi-windows-set-ctrl-handler.xml
2024-10-25 09:41:08 +03:00

153 lines
4.9 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: eee245cdbd89dc2fd908285f588e3b9e055924e5 Maintainer: rjhdby Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.sapi-windows-set-ctrl-handler" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>sapi_windows_set_ctrl_handler</refname>
<refpurpose>Установить или удалить обработчик события CTRL</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>sapi_windows_set_ctrl_handler</methodname>
<methodparam><type class="union"><type>callable</type><type>null</type></type><parameter>handler</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>add</parameter><initializer>&true;</initializer></methodparam>
</methodsynopsis>
<para>
Устанавливает или удаляет обработчик события <literal>CTRL</literal>,
который позволит процессам Windows CLI перехватывать или
игнорировать события <literal>CTRL+C</literal> и
<literal>CTRL+BREAK</literal>. Обратите внимание, что в
многопоточном окружение это возможно только при вызове
из главного потока.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>handler</parameter></term>
<listitem>
<para>
Функция обратного вызова, которая будет установлена или удалена.
Эта функция будет вызываться при наступлении событий
<keycombo action='simul'>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>
и
<keycombo action='simul'>
<keycap>CTRL</keycap>
<keycap>BREAK</keycap>
</keycombo>.
Функция должна иметь следующую сигнатуру:
<methodsynopsis>
<type>void</type><methodname>handler</methodname>
<methodparam><type>int</type><parameter>event</parameter></methodparam>
</methodsynopsis>
<variablelist>
<varlistentry>
<term><parameter>event</parameter></term>
<listitem>
<simpara>
Полученное событие <keycap>CTRL</keycap>;
<constant>PHP_WINDOWS_EVENT_CTRL_C</constant>
или <constant>PHP_WINDOWS_EVENT_CTRL_BREAK</constant>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
Установка параметра <parameter>handler</parameter> в значение
&null; приведёт к игнорированию событий
<keycombo action='simul'>
<keycap>CTRL</keycap>
<keycap>C</keycap>
</keycombo>,
но не
<keycombo action='simul'>
<keycap>CTRL</keycap>
<keycap>BREAK</keycap>
</keycombo>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>add</parameter></term>
<listitem>
<para>
Если &true;, то обработчик будет установлен. Если &false;, то
удалён.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="sapi-windows-set-ctrl-handler.example.basic">
<title>Использование <function>sapi_windows_set_ctrl_handler</function></title>
<para>
В этом примере показано, как перехватывать события <literal>CTRL</literal>.
</para>
<programlisting role="php">
<![CDATA[
<?php
function ctrl_handler(int $event)
{
switch ($event) {
case PHP_WINDOWS_EVENT_CTRL_C:
echo "Вы нажали CTRL+C\n";
break;
case PHP_WINDOWS_EVENT_CTRL_BREAK:
echo "Вы нажали CTRL+BREAK\n";
break;
}
}
sapi_windows_set_ctrl_handler('ctrl_handler');
while (true); // Бесконечный цикл
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>sapi_windows_generate_ctrl_event</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->