Sign in to follow this  
Followers 0
Cusem

Left Shift and Alt Keys stuck after function call

10 posts in this topic

I'm writing a script to remove the window captions from PokerStars table windows and to position these tables (since you can't move the tables manually without a caption). I got the _WinGetStyle and _WinSetStyle Functions from the AutoIT forums from bernd670.

Everything works fine, but after I wrote a function to reorder the tables if a table is closed or add a new table (removes the caption and repositions the new table), the LEFT SHIFT and LEFT ALT keys are stuck (pressed down). If I press them physically they are "unstuck" again.

I don't think it's Bernd's functions since I use them in other functions with no problems. It's just when I call the _CaptionAdd() function that 75% of the times I call it the left shift and alt keys are stuck. And I'm hoping somebody can tell me why this happens.

I already tried adding

Send("{SHIFTUP}")

Send("{LSHIFT UP}")

Send("{LALT UP}")

but with no results. I have to physically press the left shift button and the left alt button to release them.

These are Benrd670's functions

Func _WinSetStyle ($WinTitle, $WinText = "", $Style = -1, $ExStyle = -1)
    Local $h_window 

    $h_window = $WinTitle
    If Not IsHWnd($h_window) Then 
        $h_window = WinGetHandle($WinTitle, $WinText)
        If @error Then
            SetError(1)
        Return 0
        EndIf
    EndIf

; write Windowstyle
    If $Style = -1 Then $Style = BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)
        DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $h_window, "long", $GWL_STYLE, "long", $Style)
        If @error Then
            SetError(1)
        Return 0
    EndIf

; write extended Windowstyle
    If $ExStyle = -1 Then $ExStyle = BitOR($WS_EX_APPWINDOW ,$WS_EX_WINDOWEDGE)
        DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $h_window, "long", $GWL_EXSTYLE, "long", $ExStyle)
        If @error Then
            SetError(1)
        Return 0
    EndIf

    DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_window, "int", $WM_NCPAINT, "int", 1, "int", 0)

    SetError(0)
    Return 1
EndFunc
Func _WinGetStyle($WinTitle, $WinText = "")
    Local $RetValue[2], $Temp, $h_window

    $h_window = $WinTitle
    If Not IsHWnd($h_window) Then 
        $h_window = WinGetHandle($WinTitle, $WinText)
        If @error Then
            SetError(1)
            Return ""
        EndIf
    EndIf

; read Windowstyle
    $Temp = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $h_window, "long", $GWL_STYLE)
    If @error Then
        SetError(1)
        Return ""
    EndIf
    $RetValue[0] = $Temp[0]

; read extended Windowstyle
    $Temp = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $h_window, "long", $GWL_EXSTYLE)
    If @error Then
        SetError(1)
        Return ""
    EndIf
    $RetValue[1] = $Temp[0]

    SetError(0)
    Return $RetValue
EndFunc

And this is my function to add tables and reposition the tables

Func _CaptionAdd()
    TraySetIcon(".\Data\red.ico")
    Traytip($versie, "Removing Window Captions of added Table.."&@LF&"Input disabled until task is finished", 30, 1)
    BlockInput(1)
    Opt("MouseCoordmode", 1)
    Local $mousepos = MouseGetPos()
    Opt("MouseCoordmode", 2)
    Local $occ[10][2] = [[0, ""], [0, ""], [0, ""], [0, ""], [0, ""], [0, ""], [0, ""], [0, ""], [0, ""], [0, ""]]
    Local $posx[10]
    Local $posy[10]
    If $tablesizesetup = 0 Then;6tables
        $posx[1] = 0
        $posy[1] = 0
        $posx[2] = 640
        $posy[2] = 0
        $posx[3] = 1280
        $posy[3] = 0
        $posx[4] = 0;4
        $posy[4] = 441 
        $posx[5] = 640
        $posy[5] = 441
        $posx[6] = 1280
        $posy[6] = 441
        $posx[7] = 0;7
        $posy[7] = 759
        $posx[8] = 640
        $posy[8] = 759
        $posx[9] = 1280
        $posy[9] = 759
        $width = 690;640    
        $height = 475;441
    ElseIf $tablesizesetup = 2 Then;9tables
        $posx[1] = 90
        $posy[1] = 0
        $posx[2] = 670
        $posy[2] = 0
        $posx[3] = 1250
        $posy[3] = 0
        $posx[4] = 90;4
        $posy[4] = 400 
        $posx[5] = 670
        $posy[5] = 400
        $posx[6] = 1250
        $posy[6] = 400
        $posx[7] = 90;7
        $posy[7] = 800
        $posx[8] = 670
        $posy[8] = 800
        $posx[9] = 1250
        $posy[9] = 800
        $width = 630;580
        $height = 434;400
    EndIf
    Local $tablelist = WinList($tablename_identificationstring, "")
    Local $captiontables = 0
    
;===>>> Checks how many tables have captions and retrieves positions of tables with caption already removed
    For $a = 1 to $tablelist[0][0]
        Local $style = _WinGetStyle($tablelist[$a][0], "")
    ;Caption = 382664704 & 256
    ;NoCaption = 335544320 & 0
        If $style[0] = 382664704 AND $style[1] = 256 Then 
            $captiontables = $captiontables + 1
        Else
            Local $pos = WinGetPos($tablelist[$a][0], "")
            For $c = 1 to 9
                If $pos[0] = $posx[$c] AND $pos[1] = $posy[$c] Then 
                    $occ[$c][0] = 1
                    $occ[$c][1] = $tablelist[$a][0]
                EndIf
            Next
        EndIf
    Next
    
;===>>> Determines the last free position
    Local $freepos = 0
    For $a = 9 to 1 Step -1
        If $freepos = 0 AND $occ[$a][0] = 1 Then
            $freepos = $a + 1
        EndIf
    Next
    
;===>>> Removes Captions from tables with caption
    If $captiontables <> 0 Then
        Local $newpos = $freepos - 1
        For $b = 1 to $tablelist[0][0]
        ;MsgBox(0, "test", "$freepos = "&$freepos &@LF&"$newpos = "&$newpos&@LF&"$b = "&$b)
            Local $style = _WinGetStyle($tablelist[$b][0], "")
            If $style[0] = 382664704 AND $style[1] = 256 Then 
                ;===>>> Removes caption from window
                    WinMove($tablelist[$b][0], "", $posx[$newpos+$b], $posy[$newpos+$b], $width, $height, 1)
                    WinActivate($tablelist[$b][0])
                    MouseClick("Left", $width / 2, -30, 1, 1)
                    Local $size_outer = WinGetPos($tablelist[$b][0], "")
                    Local $size_inner = WinGetClientSize($tablelist[$b][0])
                    Local $caption_outer = WinGetPos($lobby_name, "")
                    Local $caption_innner = WinGetClientSize($lobby_name)
                    Local $caption_width = $size_outer[2] - $size_inner[0]
                    Local $caption_height = $size_outer[3] - $size_inner[1]
                    _WinSetStyle($tablelist[$b][0], "", "", $WS_BORDER)
                    WinSetState($tablelist[$b][0], "", @SW_SHOW)
                    WinMove($tablelist[$b][0], "", $posx[$newpos+$b], $posy[$newpos+$b], ($size_outer[2] - ($size_outer[2]-$size_inner[0])), ($size_outer[3]-($size_outer[3]-$size_inner[1])), 1)
                ;<<<===
                $occ[$freepos][0] = 1
                $occ[$freepos][1] = $tablelist[$b][0]
                $freepos = $freepos + 1
            EndIf
        Next
    EndIf
    
;===>>> Checks how many positions are empty
    Local $gaps = 0
    $freepos = $freepos - 1
    For $a = 1 to $freepos
        If $occ[$a][0] = 0 Then $gaps = $gaps + 1
    Next

;===>>> Fills empty positions and reorders tables
    For $a = 1 to $gaps
        Local $c = 0
        Do
            $c = $c + 1
            If $occ[$c][0] = 0 Then
                For $d = $c + 1 to $freepos
                    WinMove($occ[$d][1], "", $posx[$d-1], $posy[$d-1])
                    $occ[$d-1][0] = $occ[$d][0]
                    $occ[$d-1][1] = $occ[$d][1]
                Next
                $occ[$freepos][0] = 0
                $occ[$freepos][1] = 1
                $freepos = $freepos - 1
            EndIf
        Until $c = $freepos
    Next

    Opt("MouseCoordmode", 1)
    MouseMove($mousepos[0], $mousepos[1], 1)
    Opt("MouseCoordmode", 2)
    TraySetIcon(".\Data\Blue.ico")
    Traytip("", "", 0)
    BlockInput(0)
EndFunc

Share this post


Link to post
Share on other sites



Maybe it's my eyesight but I don't see where you used Send() to put the keys in the down position to begin with.

Also comment out those BlockInput lines in _CaptionAdd() and see what happens.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

that's what's so strange.

I don't have a Send("{xx DOWN}") in the entire script.

I tried commenting out the BlockInput lines and this seems to work! I thought I tried this earlier. Gonna do some more testing with the BlockInput lines commented out now.

Kinda strange, cause I use the BlockInput lines all over the place and this is the first Function where it causes "trouble".

Thanks for the reply!

Share this post


Link to post
Share on other sites

that's what's so strange.

I don't have a Send("{xx DOWN}") in the entire script.

I tried commenting out the BlockInput lines and this seems to work! I thought I tried this earlier. Gonna do some more testing with the BlockInput lines commented out now.

Kinda strange, cause I use the BlockInput lines all over the place and this is the first Function where it causes "trouble".

Thanks for the reply!

NP

When I see send or keyboard issues in any code that is using BlockInput, then that will be the first suspect.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Ok, it's definitely the Blockinput commands.

Really strange since I use them allover the script and never had any problem with them before.

In the _CaptionAdd() function I use them for the following reason;

The PokerStars tables don't get resized properly when using the WinMove command. The size of the table is fine according to the WinMove specified dimensions, but the table does not get resized automatically, so half of the table is visible in the new resized window. This is why I make the script click the border of the just resized window, since the content of the window does get resized. I use the Blockinput commands so I can't accidentily interfere with the coordinates.

I actually tried putting the BlockInput(1) right below ;===>>> Removes caption from window and the BlockInput(0) right below the MouseClick command a few lines later, but even this gets the Left shift and ALT key stuck.

Really strange.

If anybody knows what causes this, I'm anxious to know, however the problem is "solved".

Thanks for the help!

Share this post


Link to post
Share on other sites

I rewrote some things in the script and stumbled onto this weird problem again.

I did some googeling and found this in the AutoHotKey help file (online):

If BlockInput becomes active while the user is holding down keys, it might cause those keys to become "stuck down". This can be avoided by waiting for the keys to be released prior to turning BlockInput on, as in this example:

^!p::

KeyWait Control ; Wait for the key to be released. Use one KeyWait for each of the hotkey's modifiers.

KeyWait Alt

BlockInput On

; ... send keystrokes and mouse clicks ...

BlockInput Off

return

The function which has the BlockInputs in it actually gets called by HotkeySet("+!h", "Function"), so I guess this problem (the SHIFT and ALT key being stuck after the Function call) is the same as referred to in the autohotkey help file. I however don't know anything about autohotkey and didn't find any similar commands in AutoIT, so maybe somebody knows how to use the "solution" mentioned in the AutoHotkey helpfile in an AutoIT script?

Share this post


Link to post
Share on other sites

I rewrote some things in the script and stumbled onto this weird problem again.

I did some googeling and found this in the AutoHotKey help file (online):

The function which has the BlockInputs in it actually gets called by HotkeySet("+!h", "Function"), so I guess this problem (the SHIFT and ALT key being stuck after the Function call) is the same as referred to in the autohotkey help file. I however don't know anything about autohotkey and didn't find any similar commands in AutoIT, so maybe somebody knows how to use the "solution" mentioned in the AutoHotkey helpfile in an AutoIT script?

I was interested to see this because I didn't know BlockInput could cause this poblem, but it can ceratinly be caused with Send. With Send if the Shift key is released after the start of a send string and before the end of the send string then shift will be stuck. Same with Alt I think. The solution with Send is the same as the reference you found from AutoHotKey. In your function (as in HotkeySet("+!h", "Function")) put a little loop at the start something like this.

Func function
 $inTime = TimerInit()
 while _IsPressed("10") or _IsPressed("12");shift or Alt, could add the h key too
 if timerdiff($inTime) > 2000 then
   Msgbox(0,'Hey','let go of the Keyboard')
   $inTime = TimerInit()
 endif

 sleep(30)
wend

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I have the same problem with an other script on a different PC. This might be usefull info for debugging.

The problem described in the previous posts are with a pretty big script on my Windows XP SP2 x64 desktop PC.

I however have the same problem with a script on my Vista Ultimate x32 Laptop.

I use the following script to quickly navigate the scrollbars of the VNC Viewer. The laptop (VNC Client) is 1440x900 (or so) and desktop (host) is 1920x1200 so I have scrollbars in client view. However moving these scrollbars can be quite annoying using the touchpad, so I wrote the script below to use CTRL+[Direction KEY] to automatically move the scrollbars when needed.

Whenever I use the hotkeys, the CTRL key gets stuck in the VNC Client. I have to physically press CTRL or everything send to the VNC client will be +CTRL.

I did manage to discover a neat feature I didn't know of in Total Commander accidentally sending all kinda letters+CTRL!

HotKeySet("^{RIGHT}", "Slide_Right")
HotKeySet("^{LEFT}", "Slide_Left")
HotKeySet("^{UP}", "Slide_Up")
HotKeySet("^{DOWN}", "Slide_Down")
HotKeySet("^q", "Terminate")

$VNCHost = "CORE2E6600"

$pos = WinGetPos($VNCHost, "")
If $pos[2] <> 1456 OR $pos[3] <> 886 Then WinSetState($VNCHost, "", @SW_MAXIMIZE)

Func Slide_Right()
    Slider(725, 865, 1315, 865)
EndFunc

Func Slide_Left()
    Slider(725, 865, 260, 865)
EndFunc

Func Slide_Up()
    Slider(1440, 450, 1440, 175)
EndFunc

Func Slide_Down()
    Slider(1440, 450, 1440, 725)
EndFunc

Func Slider($x1, $y1, $x2, $y2)
    $mousepos = MouseGetPos()
    If NOT WinActive($VNCHost, "") Then
        WinActivate($VNCHost, "")
        $pos = WinGetPos($VNCHost, "")
        If $pos[2] <> 1456 OR $pos[3] <> 886 Then WinSetState($VNCHost, "", @SW_MAXIMIZE)
    EndIf
    MouseClickDrag("left", $x1, $y1, $x2, $y2, 2)
    MouseMove($mousepos[0], $mousepos[1], 0)
EndFunc

Func Terminate()
    Exit
EndFunc

While 1
    Sleep(150)
    If NOT WinExists($VNCHost, "") Then ExitLoop
WEnd

Share this post


Link to post
Share on other sites

i have the exact same problem with _isPressed() in this easy script:

#Include <Misc.au3>
$dll = DllOpen("user32.dll")
    While 1
        If _IsPressed("31", $dll) Then
            ControlSend("SNES9x", "", "", "{1}")
        ;Sleep(10)
        ;ControlSend("SNES9x", "", "", "{LSHIFT}")
        EndIf
    WEnd
 DllClose($dll)

obviously, sometimes when holding shift down while pressing 1, my shift key gets stuck and i have to manually deactivate it. has anybody found a solution or a decent workaround for this problem yet?

Share this post


Link to post
Share on other sites

#10 ·  Posted

I noticed that bug too.. and whatever I'm doing the shift key stay in 'pressed' status until I'm rebooting windows.. very annoying

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