Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3481724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:28:44+00:00 2026-05-18T10:28:44+00:00

I think I have a c++ program (I thought it was c#) that was

  • 0

I think I have a c++ program (I thought it was c#) that was written to run on a unix based system. It includes X11 calls.
Is there a way for me to compile it to run on a pc under windows xp?
I have installed mingw.

It is a ‘patch’ program written to get a piece of hardware (A DreamCheeky usb chessboard) to allow input to the SCID chess database package (I’ve got that installed in the windows version but the development of it is very much unix /tcl/tk etc)

The program is as follows.
The person who wrote it may have time to create a windows version (Or I fear may not)
But I am desperate to try to get it to work on my windows laptop.

//compile with g++ -o monitorcheeky monitorcheeky.c -L/usr/X11R6/lib -lX11

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <string.h>

#define KEY_DOWN True
#define KEY_UP False
#define KEYCODE_a 38
#define KEYCODE_b 56
#define KEYCODE_c 54
#define KEYCODE_d 40
#define KEYCODE_e 26
#define KEYCODE_f 41
#define KEYCODE_g 42
#define KEYCODE_h 43
#define KEYCODE_1 10
#define KEYCODE_2 11
#define KEYCODE_3 12
#define KEYCODE_4 13
#define KEYCODE_5 14
#define KEYCODE_6 15
#define KEYCODE_7 16
#define KEYCODE_8 17
#define KEYCODE_EQUALS 21 
#define KEYCODE_Q 24
#define KEYCODE_R 27
#define KEYCODE_B 56
#define KEYCODE_N 57
#define KEYCODE_RTN 36

Display *dpy;


// Function to create a keyboard event
XKeyEvent createKeyEvent(Display *display, Window &win,
                           Window &winRoot, bool press,
                           int keycode, int modifiers)
{
   XKeyEvent event;

   event.display     = display;
   event.window      = win;
   event.root        = winRoot;
   event.subwindow   = None;
   event.time        = CurrentTime;
   event.x           = 1;
   event.y           = 1;
   event.x_root      = 1;
   event.y_root      = 1;
   event.same_screen = True;
   event.keycode     = keycode;
   event.state       = modifiers;

   if(press)
      event.type = KeyPress;
   else
      event.type = KeyRelease;

return event;
}

int sendKeyPress(Window winRoot, char letter, int revert) {
    Window winFocus;
    int keycode;

    switch( letter ) 
    {
      case 'a':
        keycode = KEYCODE_a;
    break;
      case 'b':
        keycode = KEYCODE_b;
    break;
      case 'c':
        keycode = KEYCODE_c;
    break;
      case 'd':
        keycode = KEYCODE_d;
    break;
      case 'e':
        keycode = KEYCODE_e;
    break;
      case 'f':
        keycode = KEYCODE_f;
    break;
      case 'g':
        keycode = KEYCODE_g;
    break;
      case 'h':
        keycode = KEYCODE_h;
    break;
      case '1':
        keycode = KEYCODE_1;
    break;
      case '2':
        keycode = KEYCODE_2;
    break;
      case '3':
        keycode = KEYCODE_3;
    break;
      case '4':
        keycode = KEYCODE_4;
    break;
      case '5':
        keycode = KEYCODE_5;
    break;
      case '6':
        keycode = KEYCODE_6;
    break;
      case '7':
        keycode = KEYCODE_7;
    break;
      case '8':
        keycode = KEYCODE_8;
    break;
      default :
    keycode = KEYCODE_RTN;
     }

    XGetInputFocus(dpy, &winFocus, &revert);
    // Send a fake key press event to the window.
    XKeyEvent event = createKeyEvent(dpy, winFocus, winRoot, KEY_DOWN, keycode, 0);
    XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
    // Send a fake key release event to the window.
    event = createKeyEvent(dpy, winFocus, winRoot, KEY_UP, keycode, 0);
    XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
    XFlush(dpy);
    return 0;
}

int main() {
  int sockfd;
  int len;
  struct sockaddr_in address;
  int result;
  char input[5];  
  int revert;

  /* init */
  dpy = XOpenDisplay(NULL);
  if (!dpy) return 1;
  // Get the root window for the current display.
  Window winRoot = XDefaultRootWindow(dpy);

  sockfd = socket(AF_INET, SOCK_STREAM, 0);

  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr("127.0.0.1");
  address.sin_port = htons(8796);
  len = sizeof(address);

  result = connect(sockfd, (struct sockaddr *)&address, len);

  if (result == -1) {
    perror("oops: client1");
    return 1;
  }
  while (1) {
    read(sockfd, input ,5);
  //  printf("%s",input);
  //  fflush(stdin);

    sendKeyPress(winRoot, input[0], revert);
    sendKeyPress(winRoot, input[1], revert);
    sendKeyPress(winRoot, input[2], revert);
    sendKeyPress(winRoot, input[3], revert);
  }

  /* cleanup */
  XCloseDisplay(dpy);
  return 0;
}

thnx all

Jerry
Jerry

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:28:45+00:00Added an answer on May 18, 2026 at 10:28 am

    mingw will not be able to run it even if it compiles.

    You will need cygwin with the X server to run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that I am working on for class, I think the
I have a running dispute with a colleague. He's written a program that I'm
So I have a C program. And I don't think I can post any
Dear all,Now i have this question in my java program,I think it should be
I think I have a basic understanding of this, but am hoping that someone
I have an issue that (I think) might have to do with scope, but
I have some code that is crashing in a large system. However, the code
I have inherited a 20-year-old interactive command-line unix application that is no longer supported
I have a program that periodically polls a certain folder for log files. When
I have a program written in Java and a native launcher written in C++,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.