Keyboard shortcut sequences (ala Emacs)

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Keyboard shortcut sequences (ala Emacs)

Post by Reve_Etrange »

Hi all,

I was wondering if it was possible to define keyboard shortcut sequences, like Emacs (and other one-true-editor-wanabee) does Eg. Ctrl-x Ctrl-f.
I guess this means composite keymaps and all that--so the question is, can it be done? If no, any chance to get it sometime later?

Cheers,

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Keyboard shortcut sequences (ala Emacs)

Post by TheQwerty »

Currently no, but I'm really glad that I'm no longer the only "fool" that wants this. ;)

Today the best you can do is to use UDC to execute a script, which displays a menu, and then use access keys in the captions as the second part of the sequence.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Keyboard shortcut sequences (ala Emacs)

Post by highend »

You could write an .ahk script, that sends the necessary commands to XY. Would work, as long as all the functions are accessible via script commands...
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Keyboard shortcut sequences (ala Emacs)

Post by Reve_Etrange »

Yeah, but this means global hooks to capture the key events. I know you can filter by application class and likes, but this messes up with some apps nonetheless.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Keyboard shortcut sequences (ala Emacs)

Post by highend »

This doesn't mess with anything apart from XYplorer^^

You either restrict the keypresses to ahk_id or ahk_class (sufficient, if you don't have any other apps that use ThunderRT6FormDC)...
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Keyboard shortcut sequences (ala Emacs)

Post by Reve_Etrange »

I know this works in theory, but in practice the AHK hooks can break some applications that watch for the same keystrokes at a low level.

I already have AHK on my machine btw, and I keep it loaded in startup scripts because it works pretty well, but it is often not totally seamless.

I appreciate the suggestion anyway!

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Keyboard shortcut sequences (ala Emacs)

Post by binocular222 »

in AHK:

Code: Select all

SetTitleMatchMode, 2
ControlSend,, {Ctrl}f, XYplorer ahk_class ThunderRT6FormDC
I cannot imagine how it can messup with other window.

P.S: If you want to send/receive message to/from XYplorer, then try my AHK script here:http://www.xyplorer.com/xyfc/viewtopic. ... 233#p82412
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Keyboard shortcut sequences (ala Emacs)

Post by highend »

Code: Select all

#SingleInstance force
SendMode Input

GroupAdd, XYplorerGroup, ahk_class ThunderRT6FormDC ; XYplorerGroup

alphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Loop, parse, alphabet			;
	Transform, Ctrl%A_LoopField%, Chr, %A_Index%
return	

#IfWinActive, ahk_group XYplorerGroup
^x:: ; Ctrl + X

Input, x, L1 M
if x = %CtrlF%
{
	xyscript =
		( LTrim Join
			::focus "PI";
            tab("new");
		)
    CallXYplorerScript(xyscript)
    return
}
else if x = %CtrlH%
    CallXYplorerScript("::#156")
return
#IfWinActive

CallXYplorerScript(script)
{
	hwnd := WinExist("ahk_class ThunderRT6FormDC")
	if (hwnd)
		WinActivate, ahk_class ThunderRT6FormDC

	size := StrLen(script)
	if !(A_IsUnicode) {
	   VarSetCapacity(data, size * 2, 0)
	   StrPut(script, &data, "UTF-16")
	} else {
	   data := script
	}
	VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
	NumPut(4194305, COPYDATA, 0, "Ptr")
	NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
	NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
	result := DllCall("User32.dll\SendMessageW", "Ptr", hwnd, "UInt", 74, "Ptr", 0, "Ptr", &COPYDATA, "Ptr")
	return
}
You can send keyboard shortcut commands (from XY) via:
CallXYplorerScript("::#156")

or whole scripts via:
CallXYplorerScript(<name of variable that contains a script>)

Example included.
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Keyboard shortcut sequences (ala Emacs)

Post by Reve_Etrange »

Interesting, thank you for the effort!

How would you make a key binding for "copy current file selection to folder A:/b/c" ?
The mix of VB-ish code and win32 API makes my head reel :/

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Keyboard shortcut sequences (ala Emacs)

Post by klownboy »

Hi highend,
I was testing out your code above and I finally had success inputting a full working script. I read up on the input and transform command after seeing your code. :) This small modification worked for me. I may modify it slightly to open XY is it's not already as I did with earlier with code from binocular222. Though it's usually open, but maybe not "active".

Code: Select all

Input, x, L1 M
if x = %CtrlF%
{
    script = D:\Tools\Xyplorer\Scripts\ThumbnailViewer_exec.xys
    CallXYplorerScript(script)
    return
}
else if x = %CtrlH%
    CallXYplorerScript("::#156")
I noticed you used the variable "xyscript" in some places and "scripts" in other places so I made them all the same, "scripts". I also noticed it wouldn't work if I quoted the script. It worked fine unquoted.
Edit: I think what confused me initially was the use of "Ctrl" in the variable (e.g., CtrlF). Until I really understood what was happening with the transform and input commands, I thought it had something to do with the use of the control key. "Ctrl" could have been "pizza" and it would still work. :oops: The "x" used in the "input" variable also confused me coming right after hotkey assignment of "^x". The "x" could have been "pasta" and then the line below becomes:

Code: Select all

if pasta = %pizzaF%
Nice touch on the use of transform and input. It works great. Thanks, I hope all is well.
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Keyboard shortcut sequences (ala Emacs)

Post by highend »

Reve_Etrange wrote:Interesting, thank you for the effort!

How would you make a key binding for "copy current file selection to folder A:/b/c" ?
The mix of VB-ish code and win32 API makes my head reel :/
Just use regular XY scripting...

E.g.:

Code: Select all

xyscript = 
      ( LTrim Join
         ::copyto "D:\b\c", , , 2;
      )
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Keyboard shortcut sequences (ala Emacs)

Post by highend »

Hi Ken,
klownboy wrote:I may modify it slightly to open XY is it's not already
You mean you'll start XY?

Just add an else statement in the function.

Code: Select all

if (hwnd)
      WinActivate, ahk_class ThunderRT6FormDC
else
    RunWait, <path to your xyplorer.exe>
Though it's usually open, but maybe not "active".
You mean these hotkeys should be global because XY doesn't have to be the active window?
Possible, but I wouldn't recommend this.
You would have to use:
IfWinExist and you should make sure that e.g. emacs isn't the active window *g*
I noticed you used the variable "xyscript" in some places and "scripts" in other places so I made them all the same, "scripts".
Sure, can be done that way because "scripts" is local in the context of the function but I found it more confusing if I use the same variable name in the autorun context and in the function parameter.
"Ctrl" could have been "pizza" and it would still work.
Ctrl is just the first part of the variable name. Ofc you can name it anything you like. "x" was just ... short :) Normally I wouldn't use single character variable names but the script is so short, it doesn't matter.

Regards,
Highend
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Keyboard shortcut sequences (ala Emacs)

Post by klownboy »

Hi highend,
Thanks for the explanations. I'm not going to modify the script to start XY if it's not already. As you alluded to, this script suits the purpose of providing an Emacs style method of performing shortcuts within XY. There are so many other ways, which I already have defined, for starting XY (if it's not already) and performing numerous tasks or running scripts, etc. I did learn some by "playing" with it (i.e., learning from it :) ) using different keystrokes, scripts, and setting up a message box to indicate the ASCII code indicated by Value1. I also attempted to use "numbers" (i.e., 123456789) in lieu of the alphabet in the transform loop, but I guess the "CHR" cmd for transform doesn't work for numbers (ASCII code equivalent character code for a numbers).
Thanks again,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Post Reply