USpeak: Difference between revisions

Mavu (talk | contribs)
No edit summary
Mavu (talk | contribs)
No edit summary
Line 108: Line 108:
                                               V
                                               V
                                       [Focused Window]
                                       [Focused Window]


This can be done via simple calls to the X11 Server. Here is a snippet of how that can be done.
This can be done via simple calls to the X11 Server. Here is a snippet of how that can be done.


<code>
  // Get the currently focused window.
  // Get the currently focused window.
  XGetInputFocus(...);  
  XGetInputFocus(...);  
  // Create the event
  // Create the event
  XKeyEvent event = createKeyEvent(...);
  XKeyEvent event = createKeyEvent(...);
  // Send the KEYCODE. We can define these using XK_ constants
  // Send the KEYCODE. We can define these using XK_ constants
  XSendEvent(...);
  XSendEvent(...);
  // Resend the event to emulate the key release
  // Resend the event to emulate the key release
  event = createKeyEvent(...);
  event = createKeyEvent(...);
  XSendEvent(...);
  XSendEvent(...);
</code>
                        
                        
The above code will send one character to the window. This can be looped to generate a continuous stream (An even nicer way to do this would be set a timer delay to make it look like a typed stream).
The above code will send one character to the window. This can be looped to generate a continuous stream (An even nicer way to do this would be set a timer delay to make it look like a typed stream).