Jump to content

How to use IsPressed?


zypp0
 Share

Recommended Posts

  • Developers

You only test one time and then stick within the loop without testing:

#include <Misc.au3>
while 1
    if _IsPressed(01) Then
        msgbox("click sinistro")
    endif
    sleep(1)
wend

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

zypp0,

Welcome to the AutoIt forum. :)

You need to put the If statement inside the loop - and increase the Sleep to at least 10:

#include <Misc.au3>

HotKeySet("{ESC}", "On_Exit")

$hDLL = DllOpen("user32.dll")

While 1

    If _IsPressed("01", $hDLL) Then
        MsgBox(0, "", "click sinistro")
    EndIf

    Sleep(10)
WEnd

Func On_Exit()
    DllClose($hDLL)
    Exit
EndFunc

I also gave you a HotKey to exit the script and did what the Help file tells you to do if you call _IsPressed in a loop and opened/closed the DLL. :D

As a beginner, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. :)

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. Have fun! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 months later...

A small question on this if i may

Melbas example works fine with a message box but when i add a send command it gets weird and my comp starts responding oddly

The key i actually want it to press is the nought key above the p key because the keyboard this is to be used on doesn't have a numpad

which is why i tried Send ("{ASC 48")

can anyone tell me why it works with the message and not with the send?

ps all i want is right ctrl pressed makes 0 pressed thats all and esc to exit

HotKeySet("{ESC}", "On_Exit")
$hDLL = DllOpen("user32.dll")
While 1
    If _IsPressed("A3", $hDLL) Then
;~        MsgBox(0, "", "click sinistro")
      Send Send ("{ASC 48}")
    EndIf
    Sleep(10)
WEnd
Func On_Exit()
    DllClose($hDLL)
    Exit
EndFunc
Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

Thanks for the reboot and having to rearrange my entire desktop and folder contents! Although you did say "starts responding oddly". ;)

I can only assume that RCtrl-0 does something pretty wacky to the system, but I have no idea what. :oops:

However, after some careful exploration, I have found that you can use Send("{ASC 048}") if you wait for the RCtrl key to be released first and so do not use Send with it depressed: :doh:

#include <Misc.au3>

HotKeySet("{ESC}", "On_Exit")

$hDLL = DllOpen("user32.dll")

While 1
    If _IsPressed("A3", $hDLL) Then
        ; Wait for key to be released
        While _IsPressed("A3", $hDLL)
            Sleep(10)
        WEnd
        ;MsgBox(0, "", "click sinistro")
        Send ("{ASC 48}")
        ;Send ("0")
    EndIf
    Sleep(10)
WEnd

Func On_Exit()
    DllClose($hDLL)
    Exit
EndFunc   ;==>On_Exit

Note the Help file tells you to add a leading 0 to the ASCII code - and why are you not just sending "0" anyway? :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

thanks for the help Melba and im sorry about the code although i did warn about the unpredictable stuff, everytime i pressed F1 it gave me scite help not normal and i got funny chars in the script and had to reboot a cple times although it didnt mess anything up for me on the desktop.

I didn't use"0" because i didn't know i could, i checked the helpfile and it gave no reference for 1-0 so i used what was in the reference couldnt use numpad cmds so i went asc.

It works fine although ive since found out when he has a full screen app running it doesn't work with the app

Ill have to rethink how to send to a given app

Link to comment
Share on other sites

  • 1 year later...

zypp0,

Welcome to the AutoIt forum. :)

You need to put the If statement inside the loop - and increase the Sleep to at least 10:

#include <Misc.au3>

HotKeySet("{ESC}", "On_Exit")

$hDLL = DllOpen("user32.dll")

While 1

    If _IsPressed("01", $hDLL) Then
        MsgBox(0, "", "click sinistro")
    EndIf

    Sleep(10)
WEnd

Func On_Exit()
    DllClose($hDLL)
    Exit
EndFunc
I also gave you a HotKey to exit the script and did what the Help file tells you to do if you call _IsPressed in a loop and opened/closed the DLL. :D

As a beginner, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. :)

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. Have fun! ;)

M23

 

 

Not sure if I did something wrong, I replace "01" for "32", which is the key 2 I need... but I had to keep key 2 down so it can work. I need something when I press "2" key only once, not keep it pressed.

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