Register global hotkeys for Stop Timer

1 Answer 254 Views
Fiddler Classic
Adam
Top achievements
Rank 1
Iron
Adam asked on 15 Jul 2021, 04:27 PM | edited on 19 Jul 2021, 05:40 PM

Hello,

I have added request by timer custom code.

FiddlerApplication.UI.actCaptureScreenshot(false);

What should be added in this part to Stop Timer using hotkey?

Thanks.

Regards,

Adam

1 Answer, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 19 Jul 2021, 09:20 AM

Hello,

There are two ways to add a shortcut to a menu item with FiddlerScript. First, you can add hot key for the specific menu item by putting a & in front of the character you wish to use as a hotkey - for example "Sto&p Timer" will make the "p" key activate this menu item. Make sure that the key is unique for items in the sub menu. Then when the Fiddler window is active, press Alt-T then P to select the Stop Timer menu item.

The second way to add a shortcut is to use the way described in the post you linked. The shortcut will be global (e.g. Fiddler does not have to be the focused window in order for the shortcut to work). Be careful to not override another global shortcut (e.g. Win+G is bound to open the Game Bar in Windows 10). Open the FiddlerScript editor and:

1. in the Main() method, register your shortcut with a unique command name (in this case, Alt-J shortcut and command name "tesst")

        UI.RegisterCustomHotkey(HotkeyModifiers.Alt , Keys.J, "tesst");

2. In the ExecuteAction() method bellow it, add a case to the switch statement with the command name you chose above and the code that will be executed when the shortcut is pressed:

case "tesst":
        FiddlerApplication.Log.LogString("Execute a command or do some action here");
	return true;

Regards,
Lini
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Adam
Top achievements
Rank 1
Iron
commented on 21 Jul 2021, 07:06 PM

Hello Lini,
I have tried it, it works. Thank you so very much. I have a last doubt.
In this UI.RegisterCustomHotkey(HotkeyModifiers.Alt , Keys.J, "tesst");
This is combination of Alt+J . Can I register customhotkey for unused single keyboard key like only J or F5 etc?
Can we achieve with something like UI.RegisterCustomHotkey(Keys.J, "tesst");
This above doesn't work, but is this possible for single key?

Regards,
Adam
Lini
Telerik team
commented on 22 Jul 2021, 01:44 PM

Hi Adam,

The possible values for the first parameter of the RegisterCustomHotkey method are:

public enum HotkeyModifiers
{
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8,
}

 

The parameter is required and if you don't want a modifier, you can try passing 0 instead - 

        UI.RegisterCustomHotkey(0 , Keys.J, "tesst");

 

However, note that this is not officially supported and might break in a future Fiddler update.

Adam
Top achievements
Rank 1
Iron
commented on 29 Jul 2021, 04:52 AM

Thanks a lot Lini. It worked.

I have a last doubt with regards to abort session with hotkeys.

In the Main() method
UI.RegisterCustomHotkey(0 , Keys.J, "abort");

In the ExecuteAction() method

static function OnExecAction(sParams: String[]): Boolean {

FiddlerObject.StatusText = "ExecAction: " + sParams[0];

var sAction = sParams[0].toLowerCase();
switch (sAction) {
case "abort":
oSession.oRequest.pipeClient.End();
return true;

I get an error Variable 'oSession' has not been declared. Can we do abort session using hotkeys?

Regards,
Adam
Nick Iliev
Telerik team
commented on 29 Jul 2021, 09:59 AM

The session object is not accessible from the ExecAction method or from the global keyboard hotkeys. These hotkeys are not linked with the session events, so there is no way to access a session. 

Instead, you can create an AutoResponder rule and use the *drop action on a session object. This action will immediately close the session without sending a response.

Tags
Fiddler Classic
Asked by
Adam
Top achievements
Rank 1
Iron
Answers by
Lini
Telerik team
Share this question
or