Jump to content

_IsPressed


Recommended Posts

Hey,

I wanted to know if there was a way to do that.

I have a _IsPressed in a While loop.

But I have this problem. When the key is pressed, it detects that the key has been pressed 6-7 times (because of the time it takes to release the key).

Is there a way to know only when the key is really pressed? Not hold down.

Maybe detect when it's pressed, then wait for it to be released then pressed again to detect it again... or i don't know.

Help plz

Link to comment
Share on other sites

There is a timer on that function i think..

i toyed with it at some stage, it lets you choose how many MS to detect for or something like that.

i cant find it in the helpfile at the moment, its not painstakingly obvious.. but i am sure its there.

Either way, if it is to run a function when a certain key is pressed, try using HotKeySet() instead, its usually a lot easier.

Link to comment
Share on other sites

Can we see the script? That would help, also there is no delay choice for IsPressed.

#Include <Misc.au3>

_IsPressed ( $s_hexKey [, $v_dll = 'user32.dll' ] )

Parameters

$s_hexKey key to check for

$v_dll Optional: Handle to dll or default to user32.dll

While 1
If _IsPressed("23", $dll) Then
; Do whatever here.
    EndIf

WEnd

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

kk, first i use _IsPressed because I need to use it, I know there is hotkeys but I need to use _IsPressed

And for the code, well there isn't any for the moment. I'm just trying to make that work.

While 1
If _IsPressed("23") Then
run(@ScriptDir& "/prog1.au3")
WEnd

But it opens the prog1 like 4-6 times when I hit the key.

Link to comment
Share on other sites

kk, first i use _IsPressed because I need to use it, I know there is hotkeys but I need to use _IsPressed

And for the code, well there isn't any for the moment. I'm just trying to make that work.

While 1
If _IsPressed("23") Then
run(@ScriptDir& "/prog1.au3")
WEnd

But it opens the prog1 like 4-6 times when I hit the key.

Maybe a workaround as follows works. It will do something only the first time that _isPressed is triggered.

$keyHasBeenPressed = 0
While 1
    If _IsPressed(<key>) Then 
        If $keyHasBeenPressed = 0 Then
            ; Do Ya Thang
        EndIf
        $keyHasBeenPressed = 1
    EndIf
    
    If Not _IsPressed(<key>) Then $keyHasBeenPressed = 0
WEnd

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

But it opens the prog1 like 4-6 times when I hit the key.

Add a sleep in a Do..until loop, because whats happening is you are holding the pressed button in for such a time that it loops several times through before you release. This should hold it in a seperate loop so that it must be released to continue.

While 1
    If _IsPressed(23) then
        ;Whatever
        Do
            Sleep(100)
        Until Not _IsPressed(23)
    EndIf
WEnd
Edited by Paulie
Link to comment
Share on other sites

Add a sleep in a Do..until loop, because whats happening is you are holding the pressed button in for such a time that it loops several times through before you release. This should hold it in a seperate loop so that it must be released to continue.

While 1
    If _IsPressed(23) then
        ;Whatever
        Do
            Sleep(100)
        Until Not _IsPressed(23)
    EndIf
WEnd

This is working perfectly, but only one thing.

What is the hex key for _ (underscore) cause it's the only key that i'm not using in my game hotkey...

Link to comment
Share on other sites

This is working perfectly, but only one thing.

What is the hex key for _ (underscore) cause it's the only key that i'm not using in my game hotkey...

5f

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!"

Link to comment
Share on other sites

Christ..

Open the beta help file. Search -> _ispressed.

Function Reference

_IsPressed

--------------------------------------------------------------------------------

Check if key has been pressed

#Include <Misc.au3>

_IsPressed ( $s_hexKey [, $v_dll = 'user32.dll' ] )

Parameters

$s_hexKey key to check for

$v_dll Optional: Handle to dll or default to user32.dll

Return Value

Success: Returns 1 if true.

Failure: Returns 0 if false.

Remarks

01 Left mouse button

02 Right mouse button

04 Middle mouse button (three-button mouse)

05 Windows 2000/XP: X1 mouse button

06 Windows 2000/XP: X2 mouse button

08 BACKSPACE key

09 TAB key

0C CLEAR key

0D ENTER key

10 SHIFT key

11 CTRL key

12 ALT key

13 PAUSE key

14 CAPS LOCK key

1B ESC key

20 SPACEBAR

21 PAGE UP key

22 PAGE DOWN key

23 END key

24 HOME key

25 LEFT ARROW key

26 UP ARROW key

27 RIGHT ARROW key

28 DOWN ARROW key

29 SELECT key

2A PRINT key

2B EXECUTE key

2C PRINT SCREEN key

2D INS key

2E DEL key

30 0 key

31 1 key

32 2 key

33 3 key

34 4 key

35 5 key

36 6 key

37 7 key

38 8 key

39 9 key

41 A key

42 B key

43 C key

44 D key

45 E key

46 F key

47 G key

48 H key

49 I key

4A J key

4B K key

4C L key

4D M key

4E N key

4F O key

50 P key

51 Q key

52 R key

53 S key

54 T key

55 U key

56 V key

57 W key

58 X key

59 Y key

5A Z key

5B Left Windows key

5C Right Windows key

60 Numeric keypad 0 key

61 Numeric keypad 1 key

62 Numeric keypad 2 key

63 Numeric keypad 3 key

64 Numeric keypad 4 key

65 Numeric keypad 5 key

66 Numeric keypad 6 key

67 Numeric keypad 7 key

68 Numeric keypad 8 key

69 Numeric keypad 9 key

6A Multiply key

6B Add key

6C Separator key

6D Subtract key

6E Decimal key

6F Divide key

70 F1 key

71 F2 key

72 F3 key

73 F4 key

74 F5 key

75 F6 key

76 F7 key

77 F8 key

78 F9 key

79 F10 key

7A F11 key

7B F12 key

7C-7F F13 key - F16 key

80H-87H F17 key - F24 key

90 NUM LOCK key

91 SCROLL LOCK key

A0 Left SHIFT key

A1 Right SHIFT key

A2 Left CONTROL key

A3 Right CONTROL key

A4 Left MENU key

A5 Right MENU key

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

Christ..

Open the beta help file. Search -> _ispressed.

Function Reference

_IsPressed

--------------------------------------------------------------------------------

Check if key has been pressed

#Include <Misc.au3>

_IsPressed ( $s_hexKey [, $v_dll = 'user32.dll' ] )

Parameters

$s_hexKey key to check for

$v_dll Optional: Handle to dll or default to user32.dll

Return Value

Success: Returns 1 if true.

Failure: Returns 0 if false.

Remarks

01 Left mouse button

02 Right mouse button

04 Middle mouse button (three-button mouse)

05 Windows 2000/XP: X1 mouse button

06 Windows 2000/XP: X2 mouse button

08 BACKSPACE key

09 TAB key

0C CLEAR key

0D ENTER key

10 SHIFT key

11 CTRL key

12 ALT key

13 PAUSE key

14 CAPS LOCK key

1B ESC key

20 SPACEBAR

21 PAGE UP key

22 PAGE DOWN key

23 END key

24 HOME key

25 LEFT ARROW key

26 UP ARROW key

27 RIGHT ARROW key

28 DOWN ARROW key

29 SELECT key

2A PRINT key

2B EXECUTE key

2C PRINT SCREEN key

2D INS key

2E DEL key

30 0 key

31 1 key

32 2 key

33 3 key

34 4 key

35 5 key

36 6 key

37 7 key

38 8 key

39 9 key

41 A key

42 B key

43 C key

44 D key

45 E key

46 F key

47 G key

48 H key

49 I key

4A J key

4B K key

4C L key

4D M key

4E N key

4F O key

50 P key

51 Q key

52 R key

53 S key

54 T key

55 U key

56 V key

57 W key

58 X key

59 Y key

5A Z key

5B Left Windows key

5C Right Windows key

60 Numeric keypad 0 key

61 Numeric keypad 1 key

62 Numeric keypad 2 key

63 Numeric keypad 3 key

64 Numeric keypad 4 key

65 Numeric keypad 5 key

66 Numeric keypad 6 key

67 Numeric keypad 7 key

68 Numeric keypad 8 key

69 Numeric keypad 9 key

6A Multiply key

6B Add key

6C Separator key

6D Subtract key

6E Decimal key

6F Divide key

70 F1 key

71 F2 key

72 F3 key

73 F4 key

74 F5 key

75 F6 key

76 F7 key

77 F8 key

78 F9 key

79 F10 key

7A F11 key

7B F12 key

7C-7F F13 key - F16 key

80H-87H F17 key - F24 key

90 NUM LOCK key

91 SCROLL LOCK key

A0 Left SHIFT key

A1 Right SHIFT key

A2 Left CONTROL key

A3 Right CONTROL key

A4 Left MENU key

A5 Right MENU key

He's right, I don't see Underscore there...
Link to comment
Share on other sites

5f

First>>> I could have told you that 30 years ago

Second>>> It IS in the help file. Take a look in Appendix>Ascii Codes

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!"

Link to comment
Share on other sites

Not under _IsPressed... open helpfile, go to contents then appendix and then ASCII characters

I know, but, like you said, it is not in the _IsPressed helpfile page

I think that that list should be pitched and replaced with a link to the appendix.

That way we don't need a list thats 300 miles long on the _IsPressed Page but is still incomplete.

Link to comment
Share on other sites

I know, but, like you said, it is not in the _IsPressed helpfile page

I think that that list should be pitched and replaced with a link to the appendix.

That way we don't need a list thats 300 miles long on the _IsPressed Page but is still incomplete.

That would be nice, and it would avoid situations like these...
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

I found that this error trap for _IsPressed works:

Ant..

CODE
;

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1

sleep(50)

If _IsPressed('11', $dll) And _IsPressed('2E', $dll) then

sleep(50);hit the keys once

$PID = ProcessExists("yourchoice.exe")

If $PID then ProcessClose($PID)

Do; hold the keys

$PID = ProcessExists("yourchoice.exe")

If $PID then ProcessClose($PID)

Sleep(100)

Until Not _IsPressed('11', $dll)

$i = 0

Do; press the keys more than once

$i = $i + 1

$PID = ProcessExists("yourchoice.exe")

If $PID then ProcessClose($PID)

sleep(100)

Until $i = 100

Msgbox(0,"","Yourchoice Disabled",1)

EndIf

WEnd

Link to comment
Share on other sites

ispressed does work with [ ]

some other keys that may or not be of use with ispressed

BA: ;

BB: =

BC: ,

BD: -

BE: .

BF: /

C0: `

DB: [

DC: \

DD: ]

cheers

Funny how looking @ AutoIt Help file under ASCII Character Codes doesn't match what I've posted..

From help file:

; 3b Semicolon (does not work for me with _IsPressed , ba does work for me)

Am I reading the wrong part of the help file, or am I not translating 3b to ba by some form of formula that I missed ?

Edited by smashly
Link to comment
Share on other sites

ispressed does work with [ ]

some other keys that may or not be of use with ispressed

BA: ;

BB: =

BC: ,

BD: -

BE: .

BF: /

C0: `

DB: [

DC: \

DD: ]

cheers

Funny how looking @ AutoIt Help file under ASCII Character Codes doesn't match what I've posted..

From help file:

; 3b Semicolon (does not work for me with _IsPressed , ba does work for me)

Am I reading the wrong part of the help file, or am I not translating 3b to ba by some form of formula that I missed ?

Is there a way to make those work ( BE, BF, DC, etc.) ??? Using another dll, or I don't know.

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