program emulation of key press

Hello!
I need to programmatically check keyboard. For this reason, i need to emulate of key press. In docs i found this example:

int main(void)
{
    int data, fd, toggle = 1, error;

    /* Open the device we wish to manipulate. */
    if((fd = open ("/dev/kbd", O_RDONLY)) == -1)
    {
     fprintf(stderr, "Error with open() on /dev/kbd.  Make sure exists.\n");
     perror (NULL);
     exit(EXIT_FAILURE);
    }

    while(1)
    {
    switch(toggle)
    {
        case 1:
        {
          /*
           Turn on Num Lock and make sure that
           Caps and Scroll lock are turned off.
          */
          data = (_CONCTL_NUM_CHG | _CONCTL_NUM) | _CONCTL_CAPS_CHG |
                 _CONCTL_SCROLL_CHG;
          break;
        }
        case 2:
        {
          /*
           Turn off Num Lock and now turn on Caps Lock
           (Scroll lock is already off).
          */
          data = _CONCTL_NUM_CHG | (_CONCTL_CAPS_CHG | _CONCTL_CAPS);
          break;
        }
        case 3:
        {
          /*
           Turn off Caps lock and turn on Scroll lock
           (Num lock is already off).
          */
          data = _CONCTL_CAPS_CHG | (_CONCTL_SCROLL_CHG | _CONCTL_SCROLL);
          toggle = 0;
          break;
        }
    }

    /* Explanation below. */
    if (error = devctl (fd, DCMD_CHR_SERCTL, &data,
                        sizeof(data), NULL))
    {
        fprintf(stderr, "Error setting KBD: %s\n",
            strerror ( error ));
        exit(EXIT_FAILURE);
    }

    sleep(1);
    toggle++;
    }

    return (1);

But it’s not the actual press. It’s only a turning on Lock mode. How can i modify this code for my goal?

The code you describe shows how to manipulate the state of the shift keys on the keyboard.

I’m not sure what it is you want to do. It sounds like you want to get scan codes? Is that the case?

not exactly. I want to press key on keyboard from my own application(without real press). And after that i want to get scan codes.

I need to check the fact of having a complete set of devices (mouse, keyboard, monitor) on the KVM. Otherwise, I need to get the message about complex’s error. As I understand it, I need to interview the busy ports of KVM.

Do you mean you want to create a virtual or GUI keyboard and integrate it so that it works with applications the same as a physical keyboard?

I don’t think this is possible. For the KVM to work, it has to show the OS a keyboard and mouse even when there isn’t one physically present. It has to fool the OS into thinking one is there for when the keyboard/mouse are directed to another system.

It’s possible that the KVM firmware is smart enough to let the OS know that no keyboard or mouse is plugged in, but I doubt that it is built that way.

It is simple keyboard check. I want to send press event on every key on keyboard in series. Wihout GUI interface, only console.

It sounds like if the KVM does not support detection of devices, we can’t get this information?

I don’t know what this means. “send press event” sounds like sending a Photon event, but you say without GUI. “every key on keyboard” That sounds like you want to press each key on the physical keyboard, clearly not what you’ve been talking about.

I don’t know if that’s true or not. You will have to check with KVM. I just suggested that you probably can’t.

Sorry for my inexactitude) I’ll explain more precisely. I want to test the keyboard on a remote computer. For this, I need to write a test console application that will be run remotely. This application must send press event to each key(Esq, f1,f2,f3… q,w,e,… ,ctl,alt…) using devctl(as in the example). At the same time, pressing should be fixed with system utilities (ex. hidview-a). The problem is that I do not know the parameters of devtcl.

What you want to do is insert a character into the input stream of the console driver.
This is a feature that would have been nice, especially for building a “ditto” program
for QNX 6. Unfortunately, there does not seem to be an IOCTL that does this.

This link may help you:

sendreceivereply.wordpress.com/2 … the-usage/