Sign in to follow this  
Followers 0
Casey

ispressed within Select

6 posts in this topic

#1 ·  Posted (edited)

Hello,

Quick question. I was wondering if someone could explain why _ispressed when used within a Select statement in a While loop acts as though the key is always pressed? I am looking to understand why when I move it outside of a select statement yet still within the While loop it behaves as expected. If this isn't the expected behavior I can post the code. it is a bit long so I thought to ask first.

Thanks in advance,

Casey

Edited by Casey

Share this post


Link to post
Share on other sites



Just to clearify, you use:

Select
    Case <expression>
        statement1
        ...
EndSelect

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Just to clearify, you use:

This is what I was trying to get at.

#include <Misc.au3>
Global $CTRLpressed

;done without while returns same result

Select
    Case $CTRLpressed = _IsPressed("11")
        MsgBox(0, "", "You do see but why is that?")
    Case Else
EndSelect

$CTRLpressed = _IsPressed("11")

Select
    Case $CTRLpressed = 1
        MsgBox(0, "", "You don't see because not pressed.")
    Case Else
EndSelect

This is twice in 2 weeks that I see it after I post. I plan on stepping away from the forum to collect myself. I am very sorry. I was for some reason thinking it would only show the first message box if the return value was 1. When, if I am now correct it shows the message box regardless of the exit message.

Again, very very sorry.

Edited by Casey

Share this post


Link to post
Share on other sites

#include <Misc.au3>



While 1

    Select

    Case _IsPressed("11")

        MsgBox(0, "", "You do see but why is that?")

    Case Else

EndSelect

WEnd


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Hi Casey,

Case $CTRLpressed = _IsPressed("11")
The above code snippet does not assign the return value of _IsPressed("11") to $CTRLpressed, it compares them. You haven't yet assigned a value to $CTRLpressed so it defaults to 0/false/empty string, and so during comparison you have effectively asked "in the case where 0 is the result of _IsPressed("11").."

Perhaps something like this is what you were looking for,

#include <Misc.au3>

$dll = DllOpen("user32.dll")
While 1
    Sleep(150)
    Select
        Case _IsPressed("1B")
            MsgBox(0, "", "ESC was pressed")
        Case _IsPressed("0D")
            MsgBox(0, "", "Enter was pressed")
    EndSelect
WEnd
DllClose($dll)

Also, you may want to take a look at HotKeySet() in the helpfile.

Good luck,

-smartee

Share this post


Link to post
Share on other sites

"in the case where 0 is the result of _IsPressed("11").."

Thanks, that makes a world of difference in my understanding. I greatly appreciate it.

For $i = 50000 to 1 Step -1

Select

Case _IsPressed("11")

MsgBox(0, "", "Key is depressed, checking if _ispressed = 1")

Case Else

EndSelect

Next

For $i = 50000 to 1 Step -1

Select

Case $CTRLpressed = _IsPressed("11")

MsgBox(0, "", "Key is not depressed, checking if _ispressed = 0")

Case Else

EndSelect

Next

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