AutoRun

HotKeySet Ctrl + C does not work

14 posts in this topic

#1 ·  Posted (edited)

Hello everybody! I'm newbie and faced the problem that my simple AutoIt3 script not working properly.

When a hotkeys «Ctrl + C» or «Ctrl + V» is pressed nothing is happen.

The script running under Windows 7 64bit

I had try add #RequireAdmin to script but «Ctrl + C / V» also not give a MsgBox

However hotkey "!{ESC}" or "!{HOME}" working fine

Just example

#include <Clipboard.au3>
HotKeySet("^c", "HotKeyPressed")
HotKeySet("!{ESC}", "HotKeyPressed")    ; Abort script
While 1
        Sleep(100)
WEnd


Func HotKeyPressed()
    Switch @HotKeyPressed
        Case "^c"
            local $_clipboard = _ClipBoard_GetData($CF_UNICODETEXT)
            MsgBox(0, "From the clipboard", $_clipboard)
        Case "^v"
            MsgBox(0, "Just message", "HotKey Ctrl + V is pressed")
        Case "!{ESC}"
            Exit
    EndSwitch
EndFunc
Edited by AutoRun

Share this post


Link to post
Share on other sites



Add a MsgBox as first statement in function HotKeyPressed to check it is called at all.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Autorun,

  working fine here...

Environment(Language:0407 Keyboard:00000409 OS:WIN_7/Service Pack 1 CPU:X64 OS:X86)

You were missing a Ctrl V HKS Though.

#include <Clipboard.au3>
HotKeySet("^v", "HotKeyPressed")  ; this is missing in yours...
HotKeySet("^c", "HotKeyPressed")
HotKeySet("!{ESC}", "HotKeyPressed")    ; Abort script

While 1
        Sleep(100)
WEnd

Func HotKeyPressed()
MsgBox(0, "debug", "HotKeyPressed", .5)

    Switch @HotKeyPressed

        Case "^c"

            local $_clipboard = _ClipBoard_GetData($CF_UNICODETEXT)

            MsgBox(0, "From the clipboard", $_clipboard)

        Case "^v"

            MsgBox(0, "Just message", "HotKey Ctrl + V is pressed")

        Case "!{ESC}"

            Exit

    EndSwitch

EndFunc

cya,

Bill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

MsgBox's added. Only work with "!{ESC}" if any other hotkeys are pressed they call nothing

You were missing a Ctrl V HKS Though.

 

 

Oh, thank you. I wrote that part code for «CTRL+V» combination when already was writing the topic

Edited by AutoRun

Share this post


Link to post
Share on other sites

Which version of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0

But the system has different language and keyboard layouts:

Keyboard:00000419 

Language:0419

I think it cause problem with a capture letter keys (A-Z) for HotKeySet function.

With a single letter "c" or a "!c" or any other letter script does not any action

Not working:

HotKeySet("c", "HotKeyPressed")

What can I do that pressed letter keys were taken correctly?

Edited by AutoRun

Share this post


Link to post
Share on other sites

419 is cyrillic, right?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes it is, but keys are pressed when EN (USA) layout is choosed.

Share this post


Link to post
Share on other sites

It is very common that hotkeyset() is not tested for success.
 
I'm using an abbreviation "hk " that produces the following code which checks for errors.
 

_HotKey("{ESC}")
_HotKey("{|}")
Func _HotKey($hotkey = "")
;       ! ALT  + SHIFT  ^ CONTROL  # WinKey
    Switch @HotKeyPressed
        Case "{ESC}"
            Exit 0*MsgBox(64 + 262144, Default, "Exit", 1)
        Case "{???}"
            Beep()
            ; HotKeySet(@HotKeyPressed)
            ; send("???")
            ; HotKeySet(@HotKeyPressed,"_Hotkey")
        Case Else
            If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed)
            If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.")
    EndSwitch
EndFunc   ;==>_HotKey

While Sleep(100)     ; here should be your application.
WEnd                 ; meanwhile, here is a dummy loop.

 


 
 
 And here the code to test CNTL+c  and CNTL+v :

_HotKey("{ESC}")
_HotKey("^c")
_HotKey("^v")
Func _HotKey($hotkey = "")
;       ! ALT  + SHIFT  ^ CONTROL  # WinKey
    Switch @HotKeyPressed
        Case "{ESC}"
            Exit 0*MsgBox(64 + 262144, Default, "Exit", 1)
        Case "^c"
            Beep(1000,200)
        Case "^v"
            Beep(2000,200)
        Case Else
            If Not IsDeclared("hotkey") Then Return MsgBox(16 + 262144, Default, "No CASE statement defined for hotkey " & @HotKeyPressed)
            If HotKeySet($hotkey, "_Hotkey") = 0 Then Return MsgBox(16 + 262144, Default, "Hotkey " & $hotkey & " invalid or set by another application.")
    EndSwitch
EndFunc   ;==>_HotKey

While Sleep(100)     ; here should be your application.
WEnd                 ; meanwhile, here is a dummy loop.

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Sorry for delay with answer, my holiday was being without access to a network.

Now the codes is tested and the first returned one error "invalid or set by another application" for "{|}" and the second for both "^v" and "^c" hotkeys.

But I haven't idea for what reason it does an error :ermm:

If runing one more copy the script, it also says error for "{ESC}" hotkey.

Edited by AutoRun

Share this post


Link to post
Share on other sites

The first (in the spoiler) is the raw abbreviation code for "hk " where the "|² is a placeholder for the cursor position in the resulting code. It is not intended to be run itself.

The second shows, that there is already a hotkey set for Cntl+c and Cntl+v before you run the code.

When running it again in parallel, ESC is also already in error due to the hotkeyset in the first run.

The conclusion is that you have another program starting before this scripts that has already occupied these two hotkeys.

Unfortunately there is no method to get the owner of these hotkeys.

Just check your autostart and statup for the program.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Well, all programs with exception for Rialtek sound driver and ATI Catalyst were deleted from startup. Then reboot.

So… I do have installed antivirus KIS 2011. Although now I can launch it only manually, but can antivirus to block keys for an another program by anti-spy reason? Is sense to remove it?

Share this post


Link to post
Share on other sites

I just wrote a script and I used:

Send("{CTRLDOWN}v{CTRLUP}")

and

Send("{CTRLDOWN}c{CTRLUP}")

and it tested with a hotkeyset fine. Here is the whole script:

;Makes highlighted text either all upper or all lower case
HotKeySet("!+L","LowerCase");shift + alt + L will make highlighted text lower case
HotKeySet("!+U","UpperCase");Shift + alt + U will make highlighted text upper case
HotKeySet("ESC","Terminate");hit ESC key to exit script

While 1;Loop required to keep script running
    Sleep(100)
WEnd

Func LowerCase()
    Send("{CTRLDOWN}c{CTRLUP}");copy selected text to windows clipboard
    $Clipboard = ClipGet();Set clipboard to a local variable
    $Lower = Stringlower($Clipboard);convert all text in clipboard to uppercase
    ClipPut($Lower);put the string into the windows clipboard
    Send("{CTRLDOWN}v{CTRLUP}");paste over selected text
EndFunc

Func UpperCase()
    Send("{CTRLDOWN}c{CTRLUP}");copy selected text to windows clipboard
    $Clipboard = ClipGet();Set clipboard to a local variable
    $Upper = Stringupper($Clipboard);convert all text in clipboard to uppercase
    ClipPut($Upper);put the string into the windows clipboard
    Send("{CTRLDOWN}v{CTRLUP}");paste over selected text
EndFunc

Func Terminate
    Exit 0;exit the script
EndFunc

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Thank you guys for all tips and notes, but problem was resolved very easily.

Just need to change a code with latin letters a "C" and a "V" to cyrillic a "С" and a "M" and now it work fine.

Because as I wrote above the system has a cyrillic keyboard layout.

computergroove, little fix and it working fine for me too.

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