Sign in to follow this  
Followers 0
greymouse

Best way of multiple ispressed?

12 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@ChrisL, isn't that going to destroy another script?

I mean i use those numbers for one script, then run another that sending the keys 0-9.

I think it's not going to work so good.

Share this post


Link to post
Share on other sites

Have you tried it or are you just going to say it wont work?

It works, but it destroying the 0-9 keys for my other script.

And if i do a hotkeyset on the other script, it will destroy for the recent script.

Share this post


Link to post
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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks for all help and examples guys.

I using the guiaccelerator. And it works perfect now.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

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