Jump to content

remap shortcuts only for specific application


Recommended Posts

I just discovered AutoIt and I'm fascinated. I already did some usefull stuff and I almost don't know anything about scripting.

Is it possible to create a script which can change some default keyboard shortcuts for some software ?

Le me explain this further.

Most of the newer applications today have the option to customize their shortcuts. But some older application have fixed keyboard shortcuts (you can not change them), and some other apps don't have keyboard shortcuts at all.

- So is it possible with AutoIt to change that ?

- And even better, the AutoIt executable to start automatically with the desired program, and it should only work when that program is in focus.

- Can it be done ?

Link to comment
Share on other sites

I just discovered AutoIt and I'm fascinated. I already did some usefull stuff and I almost don't know anything about scripting.

Is it possible to create a script which can change some default keyboard shortcuts for some software ?

Le me explain this further.

Most of the newer applications today have the option to customize their shortcuts. But some older application have fixed keyboard shortcuts (you can not change them), and some other apps don't have keyboard shortcuts at all.

- So is it possible with AutoIt to change that ?

- And even better, the AutoIt executable to start automatically with the desired program, and it should only work when that program is in focus.

- Can it be done ?

Trap the keyboard, process each keypress and then transfer it to the host program?

Hmm..

Sounds like a dun dun duuuuun keylogger!!!

Nope, you'll only get flamed for that request.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

dun dun duun keyloger ? I don't know what even that means .

So le me add some more specific details. I think it's pretty complicated what I'm asking. This is not you regular remap script.

For example, Vue - a very sofisticated 3d rendering application, used even by Industrial Light and Magic for Pirates of caribbean.

I am used with the 3ds max shortcuts style. And if I work with other software I customize the shortcuts to be like in 3ds max.

Vue claims that they have specialized shortcuts specially for 3ds max, but they don't. When I complained for that in their forum, nobody gave me an answer.

So now, the tricky part : It's not some simple "press Y key" and return to Vue software - the Z key.

It's more than that. For example :

For zooming with the mouse

Press CTRL + ALT + Middle mouse button (and keeping all pressed and moving the mouse for zooming) and make the selected application think you pressed not some keys but you LEFT CLICK with the mouse some GUI button on the selected application.

Sounds complicated. Is this possible ?

Or some more simple example. Press CTRL + ALT + Middle mouse button and make the selected app think you press only the RIGHT MOUSE button.

Link to comment
Share on other sites

I just discovered AutoIt and I'm fascinated. I already did some usefull stuff and I almost don't know anything about scripting.

Is it possible to create a script which can change some default keyboard shortcuts for some software ?

Le me explain this further.

Most of the newer applications today have the option to customize their shortcuts. But some older application have fixed keyboard shortcuts (you can not change them), and some other apps don't have keyboard shortcuts at all.

- So is it possible with AutoIt to change that ?

- And even better, the AutoIt executable to start automatically with the desired program, and it should only work when that program is in focus.

- Can it be done ?

I just made something like that (although I still have problems with RightShiftKey), but here it is;

HotKeySet("+{ESC}", "_Terminate") ; You can change the key combination of this to anything you like

While 1
    If WinActive("SomeWindow") Then
        HotKeySet("+m", "_Func1") ; Shift+M will trigger _Func1
        HotKeySet("+a", "_Func2")
        HotKeySet("{F4}", "_Login")
        HotKeySet("+o", "_Func3")
        HotKeySet("+r", "_Func4")
        HotKeySet("{NUMPADENTER}", "_Enter")
    Else
        HotKeySet("+m")
        HotKeySet("+a")
        HotKeySet("{F4}")
        HotKeySet("+o")
        HotKeySet("+r")
        HotKeySet("{NUMPADENTER}")
    EndIf
WEnd

Func _Terminate()
    Exit
EndFunc

Func _Func1()
    ... ; your macro goes here
EndFunc

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

I just made something like that (although I still have problems with RightShiftKey), but here it is;

Isn't there a limit of 64 hotkeys though, or is it possible to remap the entire keyboard now?

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Yep. I just wanna change a few shortcuts. That's all. But as I said, the difficult part is the whole mouse, keyboard and GUI buttons combination. aslani I will test your script.

- I have some more questions. For example, on a 3 GHZ CPU, what will be the impact of keeping this script ON all the time as an .exe. How much processor will it use ? Especially while I work with the script ?

- Is it possible to automatically start the script when I start the targeted program ? And also automatically close ?

Link to comment
Share on other sites

Yes to both questions, and on a 3ghz machine the CPU load impact is variable, depending on how the loops are built. Generally, though, the impact won't be noticible.

Your biggest hiccup will be the modified mouse click/wheel functions. That may require explicit DLL calls.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

  • 3 years later...

Sorry for resurecting a dead thread but its basically what im dealing with...

I Used the example above and made a start to a script that id like to work on for my own use first then possibly add a small gui to it so i can throw it up for others to use... at the molment its VERY basic, i realize with a gui i would have to use either OnEvent or MessageLoop - which is one of my questions (which will make me decide if its worth bothering to add a GUI to it) but is an autoit GUI very CPU Intensive? msgloop sounds very intensive and onevent seems like it would be as bad as my script below...

Heres my script, its useing 12% of a i7 930 oc'd to 3.8ghz on a R3E with 12g 2000mhz Corsair tri-channel, was quite surprise to see 3 cores at around 5% and one at around 80% when this was in use...

HotKeySet("+{ESC}", "_Terminate") ; Exit Script

While 1

If WinActive("Windows Media Center") Then

HotKeySet("{SPACE}", "_FuncShiftP") ; Space triggers Shift+P (commonly space is pause in other programs,

HotKeySet("+a", "_Func1") ; Shift+A triggers _Func1 (in WMC its "last channel" and kills buffer)

Else

HotKeySet("{SPACE}")

HotKeySet("+a")

EndIf

WEnd

Func _Terminate()

Exit

EndFunc

Func _FuncShiftP()

Send("^p") ; Send Control+P instead of Spacebar as to pause/unpause current channel instead of change to "Last Channel"

EndFunc

Func _Func1()

mousemove(1,1,1) ; Used as testing before i ruined my own buffer that was in use, also just awaiting next command...

EndFunc

if there is a possible way to tone down this scripts CPU useage, id like to run it nearly 24/7 but i dont wanna strain my CPU like that for such a minute thing, yet its a "Going-out-of-my-mind-saver" cause i about lose it when i have a nice 2 hour buffer saved up to fast forward comercials only to change then channel and lose it all, when i just spend 2 hours wasting time just to GET that buffer, only to have to do it again directly there after...

(possibly just rambling to some, but kinda nifty fun information imho, i love my new Ceton InfiniTV 4 (4 tuners, one $2.90 rental from charter for the 4 tuner card - can save ya alot of money with a HTPC and xbox use as extenders for TV's - buy a used or no cd reader possibly as extender off craigslist <Shrug>) , only issue is fighting the cable company that doesnt want to support the CableCards M-Streams in it - but the FCC forces support so, HAH Charter! (local charter owner tried to throw out his cards and not buy new ones cause they "dont make as much money" but employee (tech that showed up) showed him the FCC letter, owner said "well im not buyin new ones so use the old ones and when they die <Shrug>" --- go figure, corperate america continuing to run the world down into the ground)

THO i did just get my 2nd tuning adapter for my InfiniTV 4, so i could just record the channel along with 3 others at the same time and FF all i want not worrying, but without the 2nd adapter (which i JUST seconds ago) got up and running, i was only able to configure 1 tuner - guess i coulda still recorded...shrug, still, i run into this problem with live TV Constantly, i donno every show i wanna watch so knowing to record it adhead of time is to much

Thanks for your help ahead of time, sorry for the off topic blabber...

...Ober

Link to comment
Share on other sites

  • Moderators

Ober,

Welcome to the AutoIt forum. :mellow:

is an autoit GUI very CPU Intensive

No - your script is using a lot of CPU because you never idle the While...WEnd loop. :)

Take a look at this modified version of your script: :)

HotKeySet("+{ESC}", "_Terminate") ; Exit Script

; Create a flag
Global $fActive = False

While 1
    Sleep(10) ; Give the CPU a bit of idle time in the loop

    If WinActive("Windows Media Center") And Not $fActive Then ; Look to see if the window is active when the flag is not set
        ; Set the HotKeys
        HotKeySet("{SPACE}", "_FuncShiftP")
        HotKeySet("+a", "_Func1")
        ; Set the flag
        $fActive = True
    ElseIf Not (WinActive("Windows Media Center")) And $fActive Then ; Look to see if the window is not active when the flag is set
        ; Clear the HotKeys
        HotKeySet("{SPACE}")
        HotKeySet("+a")
        ; Clear the flag
        $fActive = False
    EndIf
WEnd

Func _Terminate()
Exit
EndFunc

Func _FuncShiftP()
    Send("^p") ; Send Control+P instead of Spacebar as to pause/unpause current channel instead of change to "Last Channel"
EndFunc

Func _Func1()
    mousemove(1,1,1) ; Used as testing before i ruined my own buffer that was in use, also just awaiting next command...
EndFunc

Now your loop will give your CPU a chance to breathe and the HotKeys will only be set/unset when needed. :party:

All clear? Please ask if not. :)

M23

P.S.

sorry for the off topic blabber

Did not read it. :blink:

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yea, very clear, i highly appreciate it....

so 10ms is enough to let the CPU rest? that seems so little, but your the teacher! :mellow:

Then i assume the flag part is basically a difference of the script being on and running always or only when WMC is Focus, does this give the CPU basically 100% rest time when WMC is not in focus?

hehe just noticed i didnt change the label from shift P to Ctrl P when i realized i was workin with the wrong Keybind too :)

So im runnin the new script, workin great, 1% CPU Usage with highest core around 4% (other stuffs runnin too tho, IE: WMC)

I Greatly appreciate the help... quick and sweet and to the point and solved my problem completely!!

Tyvm!

...Ober

Link to comment
Share on other sites

  • Moderators

Ober,

so 10ms is enough to let the CPU rest? that seems so little

It is an eternity in CPU terms! :)

i assume the flag part is basically a difference of the script being on and running always or only when WMC is Focus, does this give the CPU basically 100% rest time when WMC is not in focus

Not quite. The flag indicates whether the HotKeys have been set, this preventing them being set/unset every pass through the loop as was the case in your original script and which contributed in some measure to the CPU load. Now each loop pass runs like this:

Sleep(10) ; Give the CPU some idle time regardless of what follows

; Is WMP active?  If so, have the HotKeys been set?  Note both parts of the AND have to be true to fire.
If WinActive("Windows Media Center") And Not $fActive Then ; "Not $fActive" is "True" when "$fActive" is "False" - Booleans take a bit of getting used to!
        ; So set the HotKeys for use
        ; Set the flag to show we have done so - now the If above will never fire as the second condition is no longer True
; Is WMP not active AND the HotKeys are set?
ElseIf Not (WinActive("Windows Media Center")) And $fActive Then
        ; So we need to clear the HotKeys
        ; And we clear the flag so that this If will not fire, but the first will the next time WMP is active
EndIf

Note that if WMP is active AND the flag is set, or if WMP is not active AND the flag is not set, absolutely nothing happens other than the Sleep(10) - that is where you save the CPU load.

Clearer? :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If i were to go to a GUI where i had basically a listing of the scripts default changed keybinds along with input boxes to customize them for the present user with an apply button, what method should i go with? in order to acomplish the same goal only with multiple keysbinds?

Thanks again!

..Ober

Link to comment
Share on other sites

  • Moderators

Ober,

So you want to enable users to have a default list of HotKeys which will be set for a defined app, but allow them to vary the specific keys if required? :mellow:

I would use an ini file to store the default lists - something along these lines:

[App_1]
Action_1=Hotkey_1
Action_2=Hotkey_2
Action_3=Hotkey_3
[App_2]
Action_1=Hotkey_1
Action_2=Hotkey_2
Action_3=Hotkey_3

You could use a combo to allow the user to choose the particular app and present the current HotKey list in an array of inputs (for the actual keys) and checkboxes (for the modifiers). These controls can then be modified by the user if required and resaved to the ini file. The code could then launch the app and set the Hotkeys.

Give it a go - sounds like a fun project to begin your AutoIt coding career. Come back if you run into difficulties. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...