<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<!-- lifted from troff+man by doclifter -->
<refentry id='xgrkeybrdman'>
<!--  Copyright \(co 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1994, 1996 X Consortium -->

<!--  Permission is hereby granted, free of charge, to any person obtaining -->
<!--  a copy of this software and associated documentation files (the -->
<!--  "Software"), to deal in the Software without restriction, including -->
<!--  without limitation the rights to use, copy, modify, merge, publish, -->
<!--  distribute, sublicense, and/or sell copies of the Software, and to -->
<!--  permit persons to whom the Software is furnished to do so, subject to -->
<!--  the following conditions: -->

<!--  The above copyright notice and this permission notice shall be included -->
<!--  in all copies or substantial portions of the Software. -->

<!--  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -->
<!--  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -->
<!--  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -->
<!--  IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -->
<!--  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -->
<!--  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -->
<!--  OTHER DEALINGS IN THE SOFTWARE. -->

<!--  Except as contained in this notice, the name of the X Consortium shall -->
<!--  not be used in advertising or otherwise to promote the sale, use or -->
<!--  other dealings in this Software without prior written authorization -->
<!--  from the X Consortium. -->

<!--  Copyright \(co 1985, 1986, 1987, 1988, 1989, 1990, 1991 by -->
<!--  Digital Equipment Corporation -->

<!--  Portions Copyright \(co 1990, 1991 by -->
<!--  Tektronix, Inc. -->

<!--  Permission to use, copy, modify and distribute this documentation for -->
<!--  any purpose and without fee is hereby granted, provided that the above -->
<!--  copyright notice appears in all copies and that both that copyright notice -->
<!--  and this permission notice appear in all copies, and that the names of -->
<!--  Digital and Tektronix not be used in in advertising or publicity pertaining -->
<!--  to this documentation without specific, written prior permission. -->
<!--  Digital and Tektronix makes no representations about the suitability -->
<!--  of this documentation for any purpose. -->
<!--  It is provided ``as is'' without express or implied warranty. -->
<!--   -->
<!--  $XFree86: xc/doc/man/X11/XGrKeybrd.man,v 1.3 2003/04/28 22:17:55 herrb Exp $ -->

<!-- .na -->
<!-- Ds listing suppressed (not used) -->
<!-- De listing suppressed (not used) -->
<!-- FD listing suppressed (not used) -->
<!-- FN listing suppressed (not used) -->
<!-- IN listing suppressed (not used) -->
<!-- C{ listing suppressed (not used) -->
<!-- C} listing suppressed (not used) -->
<!-- hN listing suppressed (not used) -->
<!-- NT listing suppressed (not used) -->
<!-- .		\" Note End \-\- doug kraft 3/85 -->
<!-- NE listing suppressed (not used) -->
<!-- .ny0 -->
<refmeta>
<refentrytitle>XGrabKeyboard</refentrytitle>
<manvolnum>3X11</manvolnum>
<refmiscinfo class='date'>__xorgversion__</refmiscinfo>
<refmiscinfo class='source'>XLIB FUNCTIONS</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>XGrabKeyboard</refname>
<refname>XUngrabKeyboard</refname>
<refpurpose>grab the keyboard</refpurpose>
</refnamediv>
<!-- body begins here -->

<refsect1 id='syntax'><title>SYNTAX</title>

<para>int XGrabKeyboard&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>&hairsp;, Window <emphasis remap='I'>grab_window</emphasis>&hairsp;,
Bool <emphasis remap='I'>owner_events</emphasis>&hairsp;, int <emphasis remap='I'>pointer_mode</emphasis>&hairsp;, int
<emphasis remap='I'>keyboard_mode</emphasis>&hairsp;, Time <emphasis remap='I'>time</emphasis>&hairsp;);</para> 

<para>int XUngrabKeyboard&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>&hairsp;, Time <emphasis remap='I'>time</emphasis>&hairsp;);</para> 
</refsect1>

<refsect1 id='arguments'><title>ARGUMENTS</title>
<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>display</emphasis></term>
  <listitem>
<para>Specifies the connection to the X server.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>grab_window</emphasis></term>
  <listitem>
<para>Specifies the grab window.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>keyboard_mode</emphasis></term>
  <listitem>
<para>Specifies further processing of keyboard events.
You can pass 
<emphasis remap='I'>&hairsp;GrabModeSync&hairsp;</emphasis>
or
<emphasis remap='I'>&hairsp;GrabModeAsync&hairsp;</emphasis>.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>owner_events</emphasis></term>
  <listitem>
<para>Specifies a Boolean value that indicates whether the keyboard events 
are to be reported as usual.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>pointer_mode</emphasis></term>
  <listitem>
<para>Specifies further processing of pointer events.
You can pass 
<emphasis remap='I'>&hairsp;GrabModeSync&hairsp;</emphasis>
or
<emphasis remap='I'>&hairsp;GrabModeAsync&hairsp;</emphasis>.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>time</emphasis></term>
  <listitem>
<para>Specifies the time.
You can pass either a timestamp or
<emphasis remap='I'>&hairsp;CurrentTime&hairsp;</emphasis>.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='description'><title>DESCRIPTION</title>
<para>The
<emphasis remap='I'>&hairsp;XGrabKeyboard&hairsp;</emphasis>
function actively grabs control of the keyboard and generates
<emphasis remap='I'>&hairsp;FocusIn&hairsp;</emphasis>
and
<emphasis remap='I'>&hairsp;FocusOut&hairsp;</emphasis>
events.
Further key events are reported only to the
grabbing client.
<emphasis remap='I'>&hairsp;XGrabKeyboard&hairsp;</emphasis>
overrides any active keyboard grab by this client.
If owner_events is 
<emphasis remap='I'>&hairsp;False&hairsp;</emphasis>,
all generated key events are reported with
respect to grab_window.  
If owner_events is 
<emphasis remap='I'>&hairsp;True&hairsp;</emphasis>
and if a generated
key event would normally be reported to this client, it is reported
normally; otherwise, the event is reported with respect to the
grab_window.  
Both 
<emphasis remap='I'>&hairsp;KeyPress&hairsp;</emphasis>
and 
<emphasis remap='I'>&hairsp;KeyRelease&hairsp;</emphasis>
events are always reported,
independent of any event selection made by the client.</para>

<para>If the keyboard_mode argument is 
<emphasis remap='I'>&hairsp;GrabModeAsync&hairsp;</emphasis>,
keyboard event processing continues
as usual. 
If the keyboard is currently frozen by this client, 
then processing of keyboard events is resumed.
If the keyboard_mode  argument is
<emphasis remap='I'>&hairsp;GrabModeSync&hairsp;</emphasis>,
the state of the keyboard (as seen by client applications) appears to freeze,
and the X server generates no further keyboard events until the
grabbing client issues a releasing 
<emphasis remap='I'>&hairsp;XAllowEvents&hairsp;</emphasis>
call or until the keyboard grab is released.
Actual keyboard changes are not lost while the keyboard is frozen; 
they are simply queued in the server for later processing.</para>

<para>If pointer_mode is 
<emphasis remap='I'>&hairsp;GrabModeAsync&hairsp;</emphasis>,
pointer event processing is unaffected
by activation of the grab.  
If pointer_mode is 
<emphasis remap='I'>&hairsp;GrabModeSync&hairsp;</emphasis>,
the state of the pointer (as seen by client applications) appears to freeze, 
and the X server generates no further pointer events 
until the grabbing client issues a releasing 
<emphasis remap='I'>&hairsp;XAllowEvents&hairsp;</emphasis>
call or until the keyboard grab is released.
Actual pointer changes are not lost while the pointer is frozen; 
they are simply queued in the server for later processing.</para>

<para>If the keyboard is actively grabbed by some other client,
<emphasis remap='I'>&hairsp;XGrabKeyboard&hairsp;</emphasis>
fails and returns
<emphasis remap='I'>&hairsp;AlreadyGrabbed&hairsp;</emphasis>.
If grab_window is not viewable,
it fails and returns
<emphasis remap='I'>&hairsp;GrabNotViewable&hairsp;</emphasis>.
If the keyboard is frozen by an active grab of another client,
it fails and returns
<emphasis remap='I'>&hairsp;GrabFrozen&hairsp;</emphasis>.
If the specified time is earlier than the last-keyboard-grab time 
or later than the current X server time,
it fails and returns
<emphasis remap='I'>&hairsp;GrabInvalidTime&hairsp;</emphasis>.
Otherwise, the last-keyboard-grab time is set to the specified time
(<emphasis remap='I'>&hairsp;CurrentTime&hairsp;</emphasis>
is replaced by the current X server time).</para>

<para><emphasis remap='I'>&hairsp;XGrabKeyboard&hairsp;</emphasis>
can generate
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>
and
<emphasis remap='I'>&hairsp;BadWindow&hairsp;</emphasis>
errors.</para>

<para>The
<emphasis remap='I'>&hairsp;XUngrabKeyboard&hairsp;</emphasis>
function
releases the keyboard and any queued events if this client has it actively grabbed from
either
<emphasis remap='I'>&hairsp;XGrabKeyboard&hairsp;</emphasis>
or
<emphasis remap='I'>&hairsp;XGrabKey&hairsp;</emphasis>.
<emphasis remap='I'>&hairsp;XUngrabKeyboard&hairsp;</emphasis>
does not release the keyboard and any queued events
if the specified time is earlier than
the last-keyboard-grab time or is later than the current X server time.
It also generates
<emphasis remap='I'>&hairsp;FocusIn&hairsp;</emphasis>
and 
<emphasis remap='I'>&hairsp;FocusOut&hairsp;</emphasis>
events.
The X server automatically performs an 
<emphasis remap='I'>&hairsp;UngrabKeyboard&hairsp;</emphasis>
request if the event window for an
active keyboard grab becomes not viewable.</para>
</refsect1>

<refsect1 id='diagnostics'><title>DIAGNOSTICS</title>
<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis></term>
  <listitem>
<para>Some numeric value falls outside the range of values accepted by the request.
Unless a specific range is specified for an argument, the full range defined
by the argument's type is accepted.  Any argument defined as a set of
alternatives can generate this error.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadWindow&hairsp;</emphasis></term>
  <listitem>
<para>A value for a Window argument does not name a defined Window.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='see_also'><title>SEE ALSO</title>
<para>XAllowEvents(3X11),
XGrabButton(3X11),
XGrabKey(3X11),
XGrabPointer(3X11)
<!-- .br -->
<userinput>Xlib - C Language X Interface</userinput></para>
</refsect1>
</refentry>

