Sign in to follow this  
Followers 0
ineedh3lp

Double functionality for the same hotkey

8 posts in this topic

#1 ·  Posted (edited)

Hello! I'm currently struggling to figure out how to make the Delete key do something in a file manager and something else outside it.

#NoTrayIcon
 
#AutoIt3Wrapper_icon=_resources\icon.ico
#AutoIt3Wrapper_Compression=0
 
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
 
HotKeySet("{DEL}", "FUNC_X2Delete")
 
While 1
    Sleep(100)
WEnd
 
Func FUNC_X2Delete()
    If WinGetState("xplorer") = 15 Then
        Send("{ALT down}9{ALT up}")
    Else
        Send("{DEL}")
;~       Send("{DEL down}{DEL up}")
    EndIf
EndFunc   ;==>FUNC_X2Delete

I basically want to replace the Del shortcut in the file manager and have it do something else, while outside it the Delete key would be just the Delete key.

Please tell me if it is even possible to do this and provide some guidelines. Thank you!

EDIT: Ah, nevermind, this solves it:

Func FUNC_X2Delete()
    If WinGetState("xplorer") = 15 Then
        Send("{ALT down}9{ALT up}")
    Else
        HotKeySet("{DEL}")
        Send("{DEL}")
        HotKeySet("{DEL}", "FUNC_X2Delete")
;~       Send("{DEL down}{DEL up}")
    EndIf
EndFunc   ;==>FUNC_X2Delete
Edited by ineedh3lp

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You need to make the hotkey function unregister and than send the hotkey when the window isnt active. Something like...

HotKeySet("{del}", "FunDelete")
While 1
    Sleep(100)
WEnd
Func FunDelete()
If WinActive("Untitled") Then
  HotKeySet("{del}")
  Send("{del}")
  HotKeySet("{del}", "FunDelete")  
Else
  MsgBox(4096,"","You clicked delete and your not in notepad.")
EndIf
EndFunc

Edit: DOH just noticed the bottom of the post! Had this pulled up than I walked out of the room.

Think thats what your looking for.

Edited by boogieoompa

Share this post


Link to post
Share on other sites

Yeah, I figured out after I read the associated help file... I didn't realize it presented the solution already

; capture and pass along a keypress
HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
    ; ... can do stuff here
    HotKeySet("{Esc}")
    Send("{Esc}")
    HotKeySet("{Esc}", "captureEsc")
EndFunc

Thanks for the reply!

Now I'm having a different issue : D Let's say I want to rename a file and delete part of its name using Delete, but because that happens in the file manager, Delete isn't actually Delete, but the assigned function... now I'm wondering how to make Del work as Delete while renaming a file. (I know I can just use backspace, but I want to keep my old habit).

Share this post


Link to post
Share on other sites

Thanks for the reference, but I'm not trying to rename a file using AutoIt, I'm renaming it manually. The issue is that I can't use the Delete key to delete part of the file's name (while in the renaming process) because Delete is already assigned to do something else while the file manager is focused and active. What I'd need here would be a way to find out (using AutoIt) if the cursors is in text edit mode (you know, the blinking cursor)- then I could unregister the Delete hotkey only while renaming the file. So, is there a way to find out through AutoIt if there's a blinking cursor active?

Share this post


Link to post
Share on other sites

Thanks for the reference, but I'm not trying to rename a file using AutoIt, I'm renaming it manually. The issue is that I can't use the Delete key to delete part of the file's name (while in the renaming process) because Delete is already assigned to do something else while the file manager is focused and active. What I'd need here would be a way to find out (using AutoIt) if the cursors is in text edit mode (you know, the blinking cursor)- then I could unregister the Delete hotkey only while renaming the file. So, is there a way to find out through AutoIt if there's a blinking cursor active?

As far as I know there is no logical statement you can make that checks for a blinking cursor (probably because there are several different types and places where this would qualify). You can however adjust your logicical clauses to be more specific so that instead of just becoming the delete key for 1 window it does it for multiple. From my previous example

[font=monospace]
HotKeySet("{del}", "FunDelete")[/font]
[font=monospace]
While 1    [/font]
[font=monospace]
   Sleep(100)[/font]
[font=monospace]
WEnd[/font]
[font=monospace]
 [/font]
[font=monospace]
Func FunDelete()[/font]
[font=monospace]
  If WinActive("Untitled") OR WinActive("Filemanager") OR WinActive("Someother window")Then  [/font]
[font=monospace]
   HotKeySet("{del}")  [/font]
[font=monospace]
   Send("{del}")  [/font]
[font=monospace]
   HotKeySet("{del}", "FunDelete")  [/font]
[font=monospace]
  Else  [/font]
[font=monospace]
   MsgBox(4096,"","You clicked delete and your not in notepad.")[/font]
[font=monospace]
  EndIf[/font]
[font=monospace]
EndFunc[/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can however adjust your logicical clauses to be more specific so that instead of just becoming the delete key for 1 window it does it for multiple

In my script, the Delete key is Delete for all windows except the file manager. That's because I do not want to use the file manager's way of deleting files and folders, so when I press Delete (only while the file manager window is active) I'm actually using my own file deletion application.

I'm going to experiment with MouseGetCursor ( ) to see if I can achieve something acceptable.

Edited by ineedh3lp

Share this post


Link to post
Share on other sites

Great if you can do it that way.

But if you are doing thin manually then why not just select with mouse and either right click, delete, or simply use the backspace key?

Just seems like much ado about nothing.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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
Sign in to follow this  
Followers 0