LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-26-2008, 09:59 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 51
Howto use xmacroplay-keys to simulate pressing ALT + RETURN ?


Hello,

Under Icewm, I would liek to maximize using Alt+Return with xmacroplay-keys .

How to do those 2 keys pressiing simulation?

Thank you
 
Old 12-26-2008, 11:37 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
I don't get what you're trying to do here. Are you talking about setting up a hotkey? Through your window manager or using a multimedia key or something?

And alt + Return? What would you want to use that combination for? Is that even possible?

(Edit: I take that back. It does seem that alt+return can be used as a hotkey. It works for me in kde. Sorry! )

In any case, there's a better and easier way to simulate keypresses now than using xmacro...xdotool. "xdotool key Alt+Return" should generate the keypresses you want.

Last edited by David the H.; 12-26-2008 at 11:45 AM.
 
Old 12-27-2008, 06:51 AM   #3
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by David the H. View Post
I don't get what you're trying to do here. Are you talking about setting up a hotkey? Through your window manager or using a multimedia key or something?

And alt + Return? What would you want to use that combination for? Is that even possible?

(Edit: I take that back. It does seem that alt+return can be used as a hotkey. It works for me in kde. Sorry! )

In any case, there's a better and easier way to simulate keypresses now than using xmacro...xdotool. "xdotool key Alt+Return" should generate the keypresses you want.
thx, i wanna xfake keys for my irexec/lirc.

So it means we have 3 possibilities given to us:
- apt-get install libfakekey0 libfakekey-dev (gcc/g++) , which is already in etch.
- http://www.semicomplete.com/projects/xdotool/ (which is getting in sid ) (I didnt know this xdotool)
- xmacro play keys , which is already in etch.
 
Old 12-27-2008, 07:10 AM   #4
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 53
The default for maximizing in icewm is alt+F10. You can uncomment it in ~/.icewm/preferences.
While you're at it, try changing it to alt+enter
 
Old 12-27-2008, 10:23 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
If you need to use xmacro, then try the following line:
Code:
echo "KeyStrPress Alt_L KeyStrPress Return KeyStrRelease Return KeyStrRelease Alt_L"| xmacroplay -d 1 :0.0
I don't know why, but I had to give it a slight delay (-d 1) or else my window manager would sometimes respond twice, leaving me where I started.


Brief xmacro tutuorial:

Basically with xmacro, you feed a text string of x events (keypresses and mouse movements) into xmacroplay, which it then "plays back" for you.

You can use xmacrorec2 to record a series of actions. Just run "xmacrorec2" (not xmacrorec, which only works on remote displays) and it will record each action you do on one line of your standard output. You can pipe this output into a text file for playback. "xmacrorec2 > textfile".

To play this back simply run "xmacroplay < textfile". Note that this will play everything back at lightning speed, so if you want to make it go slower you'll have to edit the file to add "Delay 1" (for a 1 second delay) between each action. This page shows the text strings you can use in the file.

You can also send a text string directly into xmacroplay using echo and a pipe, as I've given you above. The only other thing to remember are that you must include the display (usually :0.0 for the local display) to use in the command.


As for xmacroplay-keys, I'm not completely clear on what it does, but it looks to me like it can only be used to send single key events, and not combinations like you want here. I think it's a simplified version of xmacroplay that only sends complete keypress+keyrelease events.
 
Old 12-27-2008, 10:56 AM   #6
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
I usually runs this code below:

It works and isnt buggy as the xmacro
xmacro is not reacting well

Code:
cat XFakeKeyctrlaltleft.cpp
// Send a fake keystroke event to an X window.
// by Adam Pierce - http://www.doctort.org/adam/
// modified by veek in order to generate keystrokes that aren't marked "synthetic,"
// so the receiving application thinks it's receiving genuine keyboard input.

#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <stdio.h>
#include <string.h>

// The key code to be sent.
// A full list of available codes can be found in /usr/include/X11/keysymdef.h
#define KEYCODE XK_F7
#define KEYCODE1 XK_Alt_L
#define KEYCODE2 XK_Left
#define KEYCODE3 XK_Control_L
#define KEYPRESS 1
#define KEYRELEASE 0


main()
{
// Obtain the X11 display.
    Display *display = XOpenDisplay(0);
    if(display == NULL) {
        printf("Display not found\n");
        return -1;
    }

// Get the root window for the current display.
    Window winRoot = XDefaultRootWindow(display);

// Find the window which has the current keyboard focus.
    Window winFocus;
    int    revert;
    XGetInputFocus(display, &winFocus, &revert);

// Send ALT + LEFT key sequence to currently targeted window
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE1), KEYPRESS, 0);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE3), KEYPRESS, 0);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE2), KEYPRESS, 0);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE2), KEYRELEASE, 0);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE3), KEYRELEASE, 0);
        XTestFakeKeyEvent(display, XKeysymToKeycode(display, KEYCODE1), KEYRELEASE, 0);

// Done.
    XCloseDisplay(display);
    return 0;
}
Code:
g++ -o XFakeKeyctrlaltleft  XFakeKeyctrlaltleft.cpp `pkg-config --libs --cflags x11 xtst`
Code:
chmod +rx XFakeKeyctrlaltleft
./XFakeKeyctrlaltleft

I am lazy to make a code for the whole keyboard ...
Could be good to have a good package in debian stable, so that /usr/bin is populated

Last edited by frenchn00b; 12-27-2008 at 10:58 AM.
 
Old 12-27-2008, 01:35 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Quote:
Originally Posted by frenchn00b View Post
It works and isnt buggy as the xmacro
xmacro is not reacting well
I'd guess that's the reason xdotool was developed. It does work well, is very easy to use, and appears to be stable. And sending keystrokes and such is what it's designed to do. xmacro was really designed for a different purpose and using it as keyboard action simulator is really just a workaround.

Interesting code though. You actually compiled a binary just to simulate a single keypress? Seems like overkill to me.
 
Old 06-11-2013, 04:30 PM   #8
escolom
Member
 
Registered: Apr 2012
Location: San Francisco, cA
Distribution: Ubunto 12.04/Debian 7
Posts: 57

Rep: Reputation: Disabled
Quote:
Originally Posted by David the H. View Post
I'd guess that's the reason xdotool was developed. It does work well, is very easy to use, and appears to be stable. And sending keystrokes and such is what it's designed to do. xmacro was really designed for a different purpose and using it as keyboard action simulator is really just a workaround.

Interesting code though. You actually compiled a binary just to simulate a single keypress? Seems like overkill to me.
I know this thread is old but I just used xmacro to download all my finances from two websites and do some cleaning task in calc then append to a base database after wards email me a brief financial report to my phone! the only thing is I can't get my command/script to run in cron. someone told me here its because xmacro uses xwindows and cron does not. any suggestions?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to simulate a ENTER key pressing khaos83 Linux - Newbie 2 08-06-2008 05:41 AM
Magic reboot keys: Alt & PrintScreenSysRq pressed while pressing REISUB one at a time Pamela Linux - Newbie 10 03-21-2008 03:06 AM
No TTY when pressing Alt+F1 - 7 tribalmasters Fedora 10 08-15-2005 11:02 AM
dark screen when pressing Ctrl + Alt + Backspace or Ctrl + Alt F1-F6 in Gnome or KDE trinoo Slackware 5 01-28-2005 09:13 AM
Pressing 'alt 1' key twantrd Linux - General 2 01-07-2005 01:05 AM


All times are GMT -5. The time now is 08:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration