Jump to content

Best way of multiple ispressed?


Recommended Posts

So i need to have 10 ispressed, and that is just too many.

Any better way for a workaround to create for the numbers 0-9?

And hotkeyset is just going to take over 0-9 on the keyboard for later use.

This is the code, just overkill to use 10 of them.

I think it's going to slow down my script a lot.

If _IsPressed("30") Then
                 consolewrite("yeh")
        While _IsPressed("30")
            Sleep(10)
        WEnd
    Else
        Sleep(10)
    EndIf
Edited by greymouse
Link to comment
Share on other sites

For $i = 0 to 9
    HotkeySet($i,"_HotKey")
Next

HotKeySet("{esc}","_Quit")
While 1
    sleep(250)
WEnd


Func _HotKey()

    ConsoleWrite(@HotKeyPressed & " Pressed" & @crlf)
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    HotKeySet(@HotKeyPressed,"_HotKey")

EndFunc

Func _Quit()
    Exit
EndFunc

Link to comment
Share on other sites

  • Moderators

greymouse,

Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. :)

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

So i need to have 10 ispressed, and that is just too many.

Any better way for a workaround to create for the numbers 0-9?

And hotkeyset is just going to take over 0-9 on the keyboard for later use.

This is the code, just overkill to use 10 of them.

I think it's going to slow down my script a lot.

If _IsPressed("30") Then
                 consolewrite("yeh")
        While _IsPressed("30")
            Sleep(10)
        WEnd
    Else
        Sleep(10)
    EndIf

You didn't say you wanted 2 scripts with hotkeyset for the same keys, you said it would be slow and you wanted to send keys 0 to 9 from another script.

You could try 1 script with the hotkeys set for 0 to 9 and then you will have to use 1 of the inter script communication UDFs to share that information between the multiple scripts.

Perhaps if you give more precise information about what you are trying to achieve you'd get a more precise response.

Link to comment
Share on other sites

greymouse,

Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. :)

M23

Does it need button or something to work?

Because i use pictures instead. And does it work with array?

I tested with a array there the picture-id is stored, but didn't work at all.

You didn't say you wanted 2 scripts with hotkeyset for the same keys, you said it would be slow and you wanted to send keys 0 to 9 from another script.

You could try 1 script with the hotkeys set for 0 to 9 and then you will have to use 1 of the inter script communication UDFs to share that information between the multiple scripts.

Perhaps if you give more precise information about what you are trying to achieve you'd get a more precise response.

I don't want two scripts with hotkeyset.

I just want one with they keys. But if i use hotkey in one, i need to use it in the other script.

The first using 0-9 to change stuff. The other one is going to send 0-9.

So if i close the first one, then open the other it works perfect. But if i have the script with hotkey binded and then open the other one, it doesn't work because it's going to disable the sending keys.

Edited by greymouse
Link to comment
Share on other sites

If only 1 script has HotKeySet in I don't see why it will disable the second script from sending the keys.

If you look at what I wrote before it...

1 Sets the hotkey

2 traps the key

3 disables the hotkey

4 sends the key on

5 re-enables the hotkey

So create 2 scripts.

Number 1

;1
For $i = 0 to 9
    HotkeySet($i,"_HotKey")
Next

HotKeySet("{esc}","_Quit")
While 1
    sleep(250)
WEnd


Func _HotKey()

    ConsoleWrite(@HotKeyPressed & " Pressed" & @crlf) ;2
    HotKeySet(@HotKeyPressed) ;3
    Send(@HotKeyPressed) ;4
    HotKeySet(@HotKeyPressed,"_HotKey") ;5

EndFunc

Func _Quit()
    Exit
EndFunc

Number 2

Run("Notepad.exe")
WinWait("Untitled")
Send(0)
Send(1)
Send(2)
Send(3)
Send(4)
Send(5)
Send(6)
Send(7)
Send(8)
Send(9)

If you compile script number 1 as a console application from Scite and run it, then run script number 2, you will see that script 2 will send the keys 0 to 9, script 1 will capture them but the notepad window will still get the numbers 0 to 9 written in the text document because the function releases the key and sends it on.

Edit: added some numbers in to script 1 so hopefully you can follow what it's doing

Edited by ChrisL
Link to comment
Share on other sites

Try

The way I'd do it would be an array, with each element having the hex code for the key (if you are just using the numbers one to nine then that may not be needed) and then what send to the console if it's pressed. You can then have another element that stores whether it is currently pressed as well.

#include<Misc.au3>

Local $a[9][3] = [ _
    ["31", "1 pressed", False], _
    ["32", "2 pressed", False], _
    ["33", "3 pressed", False], _
    ["34", "4 pressed", False], _
    ["35", "5 pressed", False], _
    ["36", "6 pressed", False], _
    ["37", "7 pressed", False], _
    ["38", "8 pressed", False], _
    ["39", "9 pressed", False]]

While 1
    For $i = 0 to 8
        If _IsPressed($a[$i][0]) Then
            If $a[$i][2] Then ContinueLoop
            ConsoleWrite($a[$i][1] & @CRLF)
            $a[$i][2] = True
        ElseIf $a[$i][2] Then
            $a[$i][2] = False
        EndIf
    Next

    Sleep(10)
WEnd

Of course this can be simplified greatly to just the following if all you want is the numbers:

#include<Misc.au3>

Local $a[10]

While 1
    For $i = 0 to 9
        If _IsPressed("3" & $i) Then
            If $a[$i] Then ContinueLoop
            ConsoleWrite($i & " pressed." & @CRLF)
            $a[$i] = True
        ElseIf $a[$i] Then
            $a[$i] = False
        EndIf
    Next

    Sleep(10)
WEnd

Mat

Link to comment
Share on other sites

greymouse,

Look at GUISetAccelerators - it makes keys act in a similar fashion to HotKeys, but they only do so when your GUI is focused. That might help you. :)

M23

Thanks so much, i have been using this horrible script in the past, i did not know about these accelerators

If BitAND(WinGetState($gui), 8) Then
        If _IsPressed('11', $ipDll) And _IsPressed('4E', $ipDll) Then
            _mNew()
        ElseIf _IsPressed('11', $ipDll) And _IsPressed('4F', $ipDll) Then
            _mOpen()
        ElseIf _IsPressed('11', $ipDll) And _IsPressed('10', $ipDll) And _IsPressed('53', $ipDll) Then
            _mSave()
        ElseIf _IsPressed('11', $ipDll) And _IsPressed('53', $ipDll) Then
            _mSave($openFile)
        ElseIf _IsPressed('74', $ipDll) Then
            _mGo()
        ElseIf _IsPressed('11', $ipDll) And _IsPressed('76', $ipDll) Then
            _mCompile($openFile)
        EndIf
    EndIf

Question though will GUISetAccelerators() handle both Ctrl+S and Ctrl+Shift+S properly?

[Edit] yes works great :-)

Edited by Djarlo
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...