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 6895545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:55:21+00:00 2026-05-27T06:55:21+00:00

I’m currently trying to create a little C/C++ program which emulates a key-press on

  • 0

I’m currently trying to create a little C/C++ program which emulates a key-press on one of the Multimedia-Keys (e.g. “Pause/Play”).

To simulate the keypress I used the XTestFakeKeyEvent-function from the X11-library’s. I found a working example here on SO: Simulate keypress in a Linux C console application

My problem is, that those special keys which I intend to simulate are not to be found in the keysymdef.h-file, where the constants for the used XKeysymToKeycode-function are defined.

So, I did a little research and found this post, which brought me to the xmodmap-command. Using xmodmap -pk I got a list which does include those keys:

KeyCode Keysym (Keysym) ...
Value   Value   (Name)  ...
[...]
171     0x1008ff17 (XF86AudioNext)  0x0000 (NoSymbol)   0x1008ff17 (XF86AudioNext)  
172     0x1008ff14 (XF86AudioPlay)  0x1008ff31 (XF86AudioPause) 0x1008ff14 (XF86AudioPlay)  0x1008ff31 (XF86AudioPause) 
173     0x1008ff16 (XF86AudioPrev)  0x0000 (NoSymbol)   0x1008ff16 (XF86AudioPrev)  
174     0x1008ff15 (XF86AudioStop)  0x1008ff2c (XF86Eject)  0x1008ff15 (XF86AudioStop)  0x1008ff2c (XF86Eject)  
[...]

Using those defined values (like 172 for play/pause) as the keycodes for the XTestFakeKeyEvent-function I got it to work:

// Simulate Key-Press:
Display *display;
display = XOpenDisplay(NULL);

XTestFakeKeyEvent(display, 172, true, 0);
XTestFakeKeyEvent(display, 172, false, 0);
XFlush(display);

Now, my question is:

Can I rely on those values (the integers) to be mapped to these keys on every linux system? If not (which is what I guess), what would be the proper way to get the correct mappings dynamically (in code)?

  • 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-27T06:55:22+00:00Added an answer on May 27, 2026 at 6:55 am

    I know this is not a definitive answer, but in my experience (with a similar project) the key mappings have been the same on every Linux machine I’ve tried it on. This has been only on machines with EN/US keyboard layout. I can’t speak about keyboards with alternative layouts.

    I’m sorry if this does not answer your question completely.

    EDIT:

    I actually looked at my old project and it looks like I used these functions to get the actual keycodes:

    XStringToKeysym()
    XKeysymToKeycode()
    

    Look at the MAN pages, they are pretty self explanatory.

    I hope this helped 🙂

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.