Sign in to follow this  
Followers 0
Gogeta70

Control key is sticking

6 posts in this topic

Hey guys. I'm making a program that allows you to set text to 8 presets and then press ctrl+1-8 to copy that preset text to the clipboard and paste it into your current document. The program works fine except for one small bug: The left CTRL key likes to stick when you use one of the presets.

I'm hoping someone can help me resolve this issue :D

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)

HotKeySet("^1", "Upreset1")
HotKeySet("^2", "Upreset2")
HotKeySet("^3", "Upreset3")
HotKeySet("^4", "Upreset4")
HotKeySet("^5", "Upreset5")
HotKeySet("^6", "Upreset6")
HotKeySet("^7", "Upreset7")
HotKeySet("^8", "Upreset8")
HotKeySet("^!1", "Spreset1")
HotKeySet("^!2", "Spreset2")
HotKeySet("^!3", "Spreset3")
HotKeySet("^!4", "Spreset4")
HotKeySet("^!5", "Spreset5")
HotKeySet("^!6", "Spreset6")
HotKeySet("^!7", "Spreset7")
HotKeySet("^!8", "Spreset8")

#Include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>
#Include <Clipboard.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Gogeta70\My Documents\AUTOIT\proghelper\MainForm.kxf
$Main = GUICreate("Programmer's Copy-Paste Tool - By Gogeta70", 538, 54, 192, 124)
GUISetIcon("C:\Documents and Settings\Gogeta70\My Documents\ps2\pcsx2 0.9.6.exe")
$MenuItem1 = GUICtrlCreateMenu("&File")
$Mconfig = GUICtrlCreateMenuItem("&Config", $MenuItem1)
$Mhelp = GUICtrlCreateMenuItem("&Help", $MenuItem1)
$Mexit = GUICtrlCreateMenuItem("&Exit", $MenuItem1)
$p1 = GUICtrlCreateButton("Preset 1", 4, 4, 65, 25, $WS_GROUP)
$p2 = GUICtrlCreateButton("Preset 2", 70, 4, 65, 25, $WS_GROUP)
$p3 = GUICtrlCreateButton("Preset 3", 135, 4, 65, 25, $WS_GROUP)
$p4 = GUICtrlCreateButton("Preset 4", 202, 4, 65, 25, $WS_GROUP)
$p5 = GUICtrlCreateButton("Preset 5", 269, 4, 65, 25, $WS_GROUP)
$p6 = GUICtrlCreateButton("Preset 6", 334, 4, 65, 25, $WS_GROUP)
$p7 = GUICtrlCreateButton("Preset 7", 399, 4, 65, 25, $WS_GROUP)
$p8 = GUICtrlCreateButton("Preset 8", 466, 4, 65, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Gogeta70\My Documents\AUTOIT\proghelper\PresetForm.kxf
$Preset = GUICreate("Preset Settings", 217, 225, 280, 160)
GUISetIcon("C:\Documents and Settings\Gogeta70\My Documents\ps2\pcsx2 0.9.6.exe")
$Pedit = GUICtrlCreateEdit("", 4, 4, 209, 197, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
$PresetOk = GUICtrlCreateButton("OK", 4, 204, 101, 17, $WS_GROUP)
$PresetCancel = GUICtrlCreateButton("Cancel", 112, 204, 101, 17, $WS_GROUP)
#EndRegion ### END Koda GUI section ###
#Region ### START Koda GUI section ### Form=c:\documents and settings\gogeta70\my documents\autoit\proghelper\config.kxf
$Config = GUICreate("Configuration", 237, 62, 227, 132)
GUISetIcon("C:\Documents and Settings\Gogeta70\My Documents\ps2\pcsx2 0.9.6.exe")
$Cremember = GUICtrlCreateCheckbox("Remember My Settings", 4, 4, 133, 13)
$Cclipboard = GUICtrlCreateCheckbox("Copy Presets to Clipboard", 4, 20, 145, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Cautopaste = GUICtrlCreateCheckbox("Auto-Paste Copied Presets", 4, 40, 149, 13)
GUICtrlSetState(-1, $GUI_CHECKED)
$Cok = GUICtrlCreateButton("OK", 156, 4, 73, 25, $WS_GROUP)
$Ccancel = GUICtrlCreateButton("Cancel", 156, 32, 73, 25, $WS_GROUP)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Gogeta70\My Documents\AUTOIT\proghelper\HelpForm.kxf
$Help = GUICreate("Help", 413, 285, 310, 243)
GUISetIcon("C:\Documents and Settings\Gogeta70\My Documents\ps2\pcsx2 0.9.6.exe")
$PageControl1 = GUICtrlCreateTab(8, 8, 396, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Usage")
$Edit1 = GUICtrlCreateEdit("", 16, 36, 377, 221, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("How to use:\r\n\r\nWhen you first start the program you will see 8 buttons labeled as \r\n"&Chr(39)&"Preset 1-8"&Chr(39)&".\r\nEach preset can hold text to be used as desired. To use a preset, hold \r\nCTRL and press a number 1 through 8, and depending on you \r\nconfiguration, it will copy and paste the text into the document you"&Chr(39)&"re \r\nworking on.\r\nTo set a new preset, copy any text to your clipboard and hold down \r\nCTRL+ALT and press a number 1-8 .\r\n\r\nAdditionally, you can press any of the preset buttons to edit the preset \r\ntext manually."))
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet2 = GUICtrlCreateTabItem("Configuration")
GUICtrlSetState(-1,$GUI_SHOW)
$Edit2 = GUICtrlCreateEdit("", 16, 40, 377, 217, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("The configuration settings are as follows:\r\n\r\nRemember My Settings:\r\nWill remember your preset and configuration settings by writing them to an INI file.\r\n\r\nCopy Presets to Clipboard:\r\nWhen you press a preset hotkey (Ctrl+1-8), it will copy the preset text to your clipboard so that you can paste it at will.\r\n\r\nAuto-Paste Copied Presets:\r\nThis setting will automatically paste any preset into your current document when you hit a preset hotkey."))
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
$Hok = GUICtrlCreateButton("OK", 8, 264, 393, 17, $WS_GROUP)
#EndRegion ### END Koda GUI section ###
;END GUI

; GLOBALS

    Global $Cwindow = 0 ;Current window - 0 = main, 1 = config, 2 = preset, 3 = help
    Global $Pnum = 0 ;Used to determine preset number
    Global $PresetData[9] ;Used to hold the actual preset information
    Global $ConfSettings[3] ;Holds configuration settings
    Global $Minimized ;Tells if the main window is minimized to the tray or not

;END GLOBALS

LoadConfig()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Mexit
            If $Cwindow = 0 Then
                If $ConfSettings[2] = True Then
                    SaveConfig()
                EndIf
                Exit
            Else
                GUISetState(@SW_HIDE, $Config)
                GUISetState(@SW_HIDE, $Help)
                GUISetState(@SW_HIDE, $Preset)
                GUISetState(@SW_SHOW, $Main)
                $Cwindow = 0
            EndIf

        Case $GUI_EVENT_MINIMIZE
            $Minimized = True
            GUISetState(@SW_HIDE, $Main)

        Case $Mconfig
            GUISetState(@SW_HIDE, $Main)
            GUISetState(@SW_SHOW, $Config)
            $Cwindow = 1
        Case $Mhelp
            GUISetState(@SW_HIDE, $Main)
            GUISetState(@SW_SHOW, $Help)
            $Cwindow = 3
        Case $Cok, $Hok, $PresetOk
            GUISetState(@SW_HIDE, $Config)
            GUISetState(@SW_HIDE, $Help)
            GUISetState(@SW_HIDE, $Preset)
            GUISetState(@SW_SHOW, $Main)
            If $nMsg = $PresetOk Then
                PresetOk()
            EndIf
            If $nMsg = $Cok Then
                ConfigOk()
            EndIf

            $Cwindow = 0
        Case $PresetCancel, $Ccancel
            GUISetState(@SW_HIDE, $Config)
            GUISetState(@SW_HIDE, $Preset)
            GUISetState(@SW_SHOW, $Main)
            If $nMsg = $Ccancel Then
                ConfigCancel()
            EndIf
            $Cwindow = 0
        Case $p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8
            GUISetState(@SW_HIDE, $Main)
            GUISetState(@SW_SHOW, $Preset)
            $Cwindow = 2
            If $nMsg = $p1 Then
                $Pnum = 1
            ElseIf $nMsg = $p2 Then
                $Pnum = 2
            ElseIf $nMsg = $p3 Then
                $Pnum = 3
            ElseIf $nMsg = $p4 Then
                $Pnum = 4
            ElseIf $nMsg = $p5 Then
                $Pnum = 5
            ElseIf $nMsg = $p6 Then
                $Pnum = 6
            ElseIf $nMsg = $p7 Then
                $Pnum = 7
            ElseIf $nMsg = $p8 Then
                $Pnum = 8
            EndIf
            LoadPresetText()



    EndSwitch

    $tMsg = TrayGetMsg()
        Switch $tMsg
            Case $TRAY_EVENT_PRIMARYDOUBLE

                If $Minimized = True Then
                    GUISetState(@SW_RESTORE, $Main)
                    GUISetState(@SW_SHOW, $Main)
                    $Minimized = False
                EndIf

        EndSwitch

WEnd

Func GetWindows() ;Get a list of running programs that have a open window.
    $t = WinList()
    $m = ""
    Dim $wins[255]
    $a = 1
    For $i = 1 To $t[0][0]
        If BitAND(WinGetState($t[$i][0]), 2) AND $t[$i][1] <> "" Then
            $wins[$a] = $t[$i][1]
            $a = $a+1
        EndIf
    Next
    $wins[0] = $a
    Return $wins
EndFunc

Func GetActiveWin() ;Get the currently active window

    $wins = GetWindows()

    For $i = 1 To $wins[0]
        If BitAND(WinGetState($wins[$i]), 8) Then
            Return $wins[$i]
        EndIf
    Next

EndFunc

Func SaveConfig()

    IniWrite("Settings.ini", "Config", "Clipboard", $ConfSettings[0])
    IniWrite("Settings.ini", "Config", "Paste", $ConfSettings[1])
    IniWrite("Settings.ini", "Presets", "Preset1", _StringToHex($PresetData[1]))
    IniWrite("Settings.ini", "Presets", "Preset2", _StringToHex($PresetData[2]))
    IniWrite("Settings.ini", "Presets", "Preset3", _StringToHex($PresetData[3]))
    IniWrite("Settings.ini", "Presets", "Preset4", _StringToHex($PresetData[4]))
    IniWrite("Settings.ini", "Presets", "Preset5", _StringToHex($PresetData[5]))
    IniWrite("Settings.ini", "Presets", "Preset6", _StringToHex($PresetData[6]))
    IniWrite("Settings.ini", "Presets", "Preset7", _StringToHex($PresetData[7]))
    IniWrite("Settings.ini", "Presets", "Preset8", _StringToHex($PresetData[8]))

EndFunc

Func LoadConfig() ;Loads configuration settings from a file.

    If FileExists("Settings.ini") = 0 Then
        Return False
    EndIf

    $ConfSettings[0] = IniRead("Settings.ini", "Config", "Clipboard", "False")
    $ConfSettings[1] = IniRead("Settings.ini", "Config", "Paste", "False")
    $ConfSettings[2] = True
    $PresetData[1] = _HexToString(IniRead("Settings.ini", "Presets", "Preset1", "False"))
    $PresetData[2] = _HexToString(IniRead("Settings.ini", "Presets", "Preset2", "False"))
    $PresetData[3] = _HexToString(IniRead("Settings.ini", "Presets", "Preset3", "False"))
    $PresetData[4] = _HexToString(IniRead("Settings.ini", "Presets", "Preset4", "False"))
    $PresetData[5] = _HexToString(IniRead("Settings.ini", "Presets", "Preset5", "False"))
    $PresetData[6] = _HexToString(IniRead("Settings.ini", "Presets", "Preset6", "False"))
    $PresetData[7] = _HexToString(IniRead("Settings.ini", "Presets", "Preset7", "False"))
    $PresetData[8] = _HexToString(IniRead("Settings.ini", "Presets", "Preset8", "False"))

    If $ConfSettings[0] = "True" Then
        GUICtrlSetState($Cclipboard, $GUI_CHECKED)
    Else
        GUICtrlSetState($Cclipboard, $GUI_UNCHECKED)
    EndIf

    If $ConfSettings[1] = "True" Then
        GUICtrlSetState($Cautopaste, $GUI_CHECKED)
    Else
        GUICtrlSetState($Cautopaste, $GUI_UNCHECKED)
    EndIf

    If $ConfSettings[2] = True Then
        GUICtrlSetState($Cremember, $GUI_CHECKED)
    Else
        GUICtrlSetState($Cremember, $GUI_UNCHECKED)
    EndIf


EndFunc

Func ReadConfig() ;Reads the current configuration settings.

    If BitAND(GUICtrlRead($Cclipboard), $GUI_CHECKED) Then
        $ConfSettings[0] = True
    Else
        $ConfSettings[0] = False
    EndIf

    If BitAND(GUICtrlRead($Cautopaste), $GUI_CHECKED) Then
        $ConfSettings[1] = True
    Else
        $ConfSettings[1] = False
    EndIf

    If BitAND(GUICtrlRead($Cremember), $GUI_CHECKED) Then
        $ConfSettings[2] = True
    Else
        $ConfSettings[2] = False
    EndIf

EndFunc

Func PresetOk()

    $PresetData[$Pnum] = GUICtrlRead($Pedit)

EndFunc

Func LoadPresetText()

    GUICtrlSetData($Pedit, $PresetData[$Pnum])

EndFunc

Func ConfigOk()

    ReadConfig()

EndFunc

Func ConfigCancel()

    If BitAND(GUICtrlRead($Cclipboard), $GUI_CHECKED) And $ConfSettings[0] = False Then
        GUICtrlSetState($Cclipboard, $GUI_UNCHECKED)
    EndIf
    If BitAND(GUICtrlRead($Cclipboard), $GUI_UNCHECKED) And $ConfSettings[0] = True Then
        GUICtrlSetState($Cclipboard, $GUI_CHECKED)
    EndIf

    If BitAND(GUICtrlRead($Cautopaste), $GUI_CHECKED) And $ConfSettings[1] = False Then
        GUICtrlSetState($Cautopaste, $GUI_UNCHECKED)
    EndIf
    If BitAND(GUICtrlRead($Cautopaste), $GUI_UNCHECKED) And $ConfSettings[1] = True Then
        GUICtrlSetState($Cautopaste, $GUI_CHECKED)
    EndIf
    If BitAND(GUICtrlRead($Cremember), $GUI_CHECKED) And $ConfSettings[2] = False Then
        GUICtrlSetState($Cremember, $GUI_UNCHECKED)
    EndIf
    If BitAND(GUICtrlRead($Cremember), $GUI_UNCHECKED) And $ConfSettings[2] = True Then
        GUICtrlSetState($Cremember, $GUI_CHECKED)
    EndIf

EndFunc

Func UsePreset()

    If $ConfSettings[0] = True Then
        _ClipBoard_SetData($PresetData[$Pnum], $CF_TEXT)
    EndIf

    If $ConfSettings[1] = True Then
        $window = GetActiveWin()
        Send("^v")
    EndIf

EndFunc

Func SetPreset()

    $temp = _ClipBoard_GetData($CF_TEXT)
    $PresetData[$Pnum] = $temp

EndFunc

Func Upreset1()

    $Pnum = 1
    UsePreset()

EndFunc
Func Upreset2()

    $Pnum = 2
    UsePreset()

EndFunc
Func Upreset3()

    $Pnum = 3
    UsePreset()

EndFunc
Func Upreset4()

    $Pnum = 4
    UsePreset()

EndFunc
Func Upreset5()

    $Pnum = 5
    UsePreset()

EndFunc
Func Upreset6()

    $Pnum = 6
    UsePreset()

EndFunc
Func Upreset7()

    $Pnum = 7
    UsePreset()

EndFunc
Func Upreset8()

    $Pnum = 8
    UsePreset()

EndFunc

Func Spreset1()

    $Pnum = 1
    SetPreset()

EndFunc
Func Spreset2()

    $Pnum = 2
    SetPreset()

EndFunc
Func Spreset3()

    $Pnum = 3
    SetPreset()

EndFunc
Func Spreset4()

    $Pnum = 4
    SetPreset()

EndFunc
Func Spreset5()

    $Pnum = 5
    SetPreset()

EndFunc
Func Spreset6()

    $Pnum = 6
    SetPreset()

EndFunc
Func Spreset7()

    $Pnum = 7
    SetPreset()

EndFunc
Func Spreset8()

    $Pnum = 8
    SetPreset()

EndFunc

Share this post


Link to post
Share on other sites



Maybe try the sending a {CTRLUP} key after each key press to release it? Hope this helps :|

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I tried using the {LCTRL UP} thing but it didn't work. I did, however, find a solution.

I replaced the Send() command with the following:

$ctrl = ControlGetFocus($window)
$tmp = ControlGetText($window, "", $ctrl)
ControlCommand($window, "", $ctrl, "EditPaste", $PresetData[$Pnum])

Thanks for your help.

Edited by Gogeta70

Share this post


Link to post
Share on other sites

Has anyone else had this issue - I am not able to use the code listed from OP as I am pasting in different applications. Is there a work around for this issue?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

This is a known issue, and there are a large number of work-arounds in the forums. One is here, the FAQ item on this is here.


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This is a known issue, and there are a large number of work-arounds in the forums. One is here, the FAQ item on this is here.

I did not know that - lol

I did find my own work around using the following at the top of my script looks like it resolved the issue - can someone else verify that it works for them too?

Opt('SendKeyDelay', 0)

Opt('SendKeyDownDelay' , 0)

EDIT - it did not resolve the issue - used the FAQ example

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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