Jump to content

Having some issues with hotkeyset


Recommended Posts

Hey all.  So I am trying to build a tray-based application which will counter this web page which has stupidly disallowed pasting content into the form by, when the specific menu tray item is checked, will allow a hot key to send information to using simulated key strokes rather than pasting it.  The issue I am having is quite frustrating.  I have gotten it to partially work, but whatever button I designate as the "base" for the hot key (for example, if hotkey were set to "!d", ALT would be the base) is held down throughout the execution of the function that it calls and even after it is done executing, and it causes odd behavior until I physically press the base key (ALT) on my keyboard before it will release and go back to norm.  I can't use Accelerator keys because I don't have a GUI, and this happens every time, even if I simulate a "Send" function of the base key within the function the hotkey calls.  Below is my code.  Can someone please explain what is going on?  

 

; *** Start added by AutoIt3Wrapper ***
#include <TrayConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)
HotKeySet ("!z", "paste")
TraySetClick ( 9 )
$item1 = TrayCreateItem ( "Enable" )
TrayItemSetState ( -1, $TRAY_CHECKED )
TrayCreateItem ("")
$item2 = TrayCreateItem ( "About" )
TrayCreateItem ("")
$item3 = TrayCreateItem ( "Exit" )

TraySetState ( $TRAY_ICONSTATE_SHOW )
If TrayItemGetState ( $item1 ) = 65 Then
    Beep ()
EndIf

While 1
    Switch TrayGetMsg()
        Case $item3
            Exit
        Case $item2

    EndSwitch
WEnd

Func paste ()
    Send ("!")
    If TrayItemGetState ( $item1 ) = 65 Then
        $string = StringSplit ( ClipGet (), "" )
        For $i = 1 To $string[0] Step 1
            If $string[$i] == "," Then
                Send ( "{TAB}", 0 )
                ContinueLoop
            ElseIf $string[$i] == "(" Then
                ContinueLoop
            ElseIf $string[$i] == ")" Then
                ContinueLoop
            ElseIf $string[$i] == "-" Then
                ContinueLoop
            Else
                Send ( $string[$i], 0 )
            EndIf
        Next

    Else
        TrayTip ( "Script not enabled", "You need to enable the script in order for the hotkey to apply.", 10, $TIP_ICONHAND )
    EndIf
EndFunc

 

Link to comment
Share on other sites

Do it this way:

Func paste ()
    HotKeySet ("!z")
    Send ("!")
    If TrayItemGetState ( $item1 ) = 65 Then
        $string = StringSplit ( ClipGet (), "" )
        For $i = 1 To $string[0] Step 1
            If $string[$i] == "," Then
                Send ( "{TAB}", 0 )
                ContinueLoop
            ElseIf $string[$i] == "(" Then
                ContinueLoop
            ElseIf $string[$i] == ")" Then
                ContinueLoop
            ElseIf $string[$i] == "-" Then
                ContinueLoop
            Else
                Send ( $string[$i], 0 )
            EndIf
        Next

    Else
        TrayTip ( "Script not enabled", "You need to enable the script in order for the hotkey to apply.", 10, $TIP_ICONHAND )
    EndIf
    HotKeySet ("!z", "paste")
EndFunc

to avoid sending the hotkey for paste.

Link to comment
Share on other sites

On 10/14/2016 at 10:44 PM, AutoBert said:

Do it this way:

Func paste ()
    HotKeySet ("!z")
    Send ("!")
    If TrayItemGetState ( $item1 ) = 65 Then
        $string = StringSplit ( ClipGet (), "" )
        For $i = 1 To $string[0] Step 1
            If $string[$i] == "," Then
                Send ( "{TAB}", 0 )
                ContinueLoop
            ElseIf $string[$i] == "(" Then
                ContinueLoop
            ElseIf $string[$i] == ")" Then
                ContinueLoop
            ElseIf $string[$i] == "-" Then
                ContinueLoop
            Else
                Send ( $string[$i], 0 )
            EndIf
        Next

    Else
        TrayTip ( "Script not enabled", "You need to enable the script in order for the hotkey to apply.", 10, $TIP_ICONHAND )
    EndIf
    HotKeySet ("!z", "paste")
EndFunc

to avoid sending the hotkey for paste.

Hey man.  Sorry to burst your bubble, but I copied and pasted the above code you provided (which I notice came from the help file for Hotkeyset, as I looked there too to try and solve this issue), but it still did the same thing.  The computer was acting as if "ALT" was held down throughout the function while the Send was sending the typed keys to the input box.   So, for example, I copied "3721 Cherokee St NW, Kennesaw, GA 30144" into the clipboard, and when I used my script to send it, what actually came out in the input box was "71ketWenswA044".  This is after the changes you suggested.  Thanks for trying, but still in need of a solution if anybody knows.....  

Edited by MattHiggs
Link to comment
Share on other sites

On 10/14/2016 at 10:44 PM, AutoBert said:

Do it this way:

Func paste ()
    HotKeySet ("!z")
    Send ("!")
    If TrayItemGetState ( $item1 ) = 65 Then
        $string = StringSplit ( ClipGet (), "" )
        For $i = 1 To $string[0] Step 1
            If $string[$i] == "," Then
                Send ( "{TAB}", 0 )
                ContinueLoop
            ElseIf $string[$i] == "(" Then
                ContinueLoop
            ElseIf $string[$i] == ")" Then
                ContinueLoop
            ElseIf $string[$i] == "-" Then
                ContinueLoop
            Else
                Send ( $string[$i], 0 )
            EndIf
        Next

    Else
        TrayTip ( "Script not enabled", "You need to enable the script in order for the hotkey to apply.", 10, $TIP_ICONHAND )
    EndIf
    HotKeySet ("!z", "paste")
EndFunc

to avoid sending the hotkey for paste.

And if you don't mind me asking, what do you mean by "to avoid sending the hotkey for paste"?  I'm not sure I understand what you mean by that.

Link to comment
Share on other sites

HotkeySet works proberly, it's the send which makes the trouble. Don't send ALT to switch to target application use WinWaitActive instead.

; *** Start added by AutoIt3Wrapper ***
#include <TrayConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

HotKeySet ("!z", "paste")
TraySetClick ( 9 )
$item1 = TrayCreateItem ( "Enable" )
TrayItemSetState ( -1, $TRAY_CHECKED )
TrayCreateItem ("")
$item2 = TrayCreateItem ( "About" )
TrayCreateItem ("")
$item3 = TrayCreateItem ( "Exit" )

TraySetState ( $TRAY_ICONSTATE_SHOW )
If TrayItemGetState ( $item1 ) = 65 Then
    Beep ()
EndIf

While 1
    Switch TrayGetMsg()
        Case $item3
            Exit
        Case $item2

    EndSwitch
WEnd

Func paste ()
    HotKeySet ("!z")
    ;Send ("!")
    Local $iPid=winwaitactive('send.txt','',10)
    If Not $iPid Then Exit ;MsgBox
    If TrayItemGetState ( $item1 ) = 65 Then
        $string = StringSplit ( ClipGet (), "" )
        For $i = 1 To $string[0] Step 1
            If $string[$i] == "," Then
                Send ( "{TAB}", 0 )
                ContinueLoop
            ElseIf $string[$i] == "(" Then
                ContinueLoop
            ElseIf $string[$i] == ")" Then
                ContinueLoop
            ElseIf $string[$i] == "-" Then
                ContinueLoop
            Else
                Send ( $string[$i], 1 )
            EndIf
        Next

    Else
        TrayTip ( "Script not enabled", "You need to enable the script in order for the hotkey to apply.", 10, $TIP_ICONHAND )
    EndIf
    HotKeySet ("!z", "paste")
EndFunc

 

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...