Sign in to follow this  
Followers 0
Xichael

_IsPressed for finding send key code?

35 posts in this topic

#1 ·  Posted (edited)

I'm trying to find the send key code (or whatever it's called) for a funny little button on my laptop. I found this script somewhere in the forum:

#include <misc.au3>
While 1
    sleep(10)
    For $i = 0 to 255
        if (_IsPressed(Hex($i))) Then
            MsgBox(0, "", "You pressed the: " & Chr($i) & " Key!" & @CRLF & "Which would be polled with: _Ispressed(" & $i & ")")
        EndIf
    Next
WEnd

Pressing the button while this script is running tells me:

You pressed the: ÿ Key!
which would be polled with: _Ispressed(255)

So how can I now use this information in a HotKeySet like in this script:

#NoTrayIcon

HotKeySet ("_IsPressed goes here?", "Monoff")

While 1
      Sleep(50)
WEnd
  
Func Monoff()
    Run("C:\Program Files\Monoff4.exe")
EndFunc

I've tried putting ÿ, _Ispressed(255), and just 255 in the HotKeySet, none of which worked. In AutoHotkey this button goes by SC112, but not so in AutoIt. How can I find and use this button's send key code?

Your help is much appreciated...

Edited by Xichael

Share this post


Link to post
Share on other sites



HotKeySet(Chr(225),"Monoff")


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

HotKeySet(Chr(225),"Monoff")

That didn't do it, sad to say... Any other suggestions?

Share this post


Link to post
Share on other sites

That didn't do it, sad to say... Any other suggestions?

Only that maybe you could simply check using _IsPressed(225) in your main loop instead of using a hotkey. Something like

while something;main loop
.
.
.
If _IsPressed(225) then
 Monoff()
 while _IsPressed(225)
  wend
endif


wend;end of main loop

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The If _IsPressed(255) then line has an "If ^ERROR" of an "unknown function name"... Then again, I don't really know how these things work (I'm new to AutoIt).

How exactly would it fit into my script?

I've tried:

While 1
    If _IsPressed(255) then
        Monoff()
        While _IsPressed(255)
            WEnd
    EndIf
WEnd

Func Monoff()
    Run("C:\Program Files\Monoff4.exe")
EndFunc

Is this roughly how it would work?

Share this post


Link to post
Share on other sites

Yes!

Share this post


Link to post
Share on other sites

Why the error when I run it?

post-32090-1203734845_thumb.jpg

Share this post


Link to post
Share on other sites

Error messages are incredibly helpful. It doesn't know what _ispressed is. You probably forgot the include file. misc.au3 if I remember correctly.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

...You probably forgot the include file. misc.au3...

Thanks, that got rid of the error, but the script still doesn't work. What else could be missing? Edited by Xichael

Share this post


Link to post
Share on other sites

Error messages are incredibly helpful. It doesn't know what _ispressed is. You probably forgot the include file. misc.au3 if I remember correctly.

Looks like you have written 255 but it should be 225 shouldn't it?

You should add some debugging code if it still doesn't work. ConsoleWrite is very useful for that.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Sorry, the above 225 was a typo. I just fixed it.

Will this still need a debugging now that there aren't any errors? The misc.au3 include fixed the error I was getting. Now my problem is that the script just won't do anything.

I can't get any key to work with with IsPressed. For instance, _IsPressed(90), which should be the z key, won't run the function any more than 255 will...

Here's the current script:

#include <misc.au3>

While 1
    If _IsPressed(255) then
        Monoff()
        While _IsPressed(255)
            WEnd
    EndIf
WEnd

Func Monoff()
    Run("C:\Program Files\Monoff4.exe")
EndFunc

Can anyone tell me what's wrong?

Edited by Xichael

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I tried editing this to see if it would work and it works fine for me:

#include <misc.au3>

While 1
    If _IsPressed('5A') then
        Monoff()
        While _IsPressed('5A')
            WEnd
    EndIf
WEnd

Func Monoff()
    ConsoleWrite('!> Check...' & @CRLF)
;~   Run("C:\Program Files\Monoff4.exe")
EndFunc
Try to see if you are getting to the ConsoleWrite line I added. If you are then your Run command isn't working...

Edit: '5A' = z

Edited by Achilles

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

I tried this on my MediaDirect button and start button but it didn't work

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

'5A' = z

It's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all. Edited by Xichael

Share this post


Link to post
Share on other sites

It's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all.

The helpfile is my magic book. Look up _IsPressed and it should have an incomplete but very long list. Look Contents --> AutoIt --> Appendix --> ASCII Characters for a complete list (in the helpfile also)...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

It's true, and the script is finally working! What are you using to find out that 5A = z? The script I'm using (posted above) tells me 90 = z... Could you post a copy of the IsPressed key revealing script that you're using? It would seem that the MediaDirect button isn't 255 at all.

For the record, 0x5A = 90.

And _IsPressed works correctly only if you pass hex string to it, it does not support numbers.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

So the help file says 255 is FF, but when I run the script with FF, the function just runs immediately, without waiting for a keypress. This MediaDirect button obviously isn't 255/FF, so is there some other script that can output the proper dec/hex value of this button? The script I've used is either wrong, or there's just no way for AutoIt to detect this button. The latter would be odd, as AutoHotkey (which is based on AutoIt, no?) has no problem using it (MediaDirect button = SC112)... This can't be a lost cause, can it?

Share this post


Link to post
Share on other sites

I'm just guessing now, but it seems odd to me that the very last value in your for next loop is 255 and that's what you got for the value of your key. What happens if you have a loop that goes to 300 or something? That's probably won't work but who knows...


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

If it involves scan codes, most likely you'll have to use keyboard hook. Luckily for you nowadays that isn't very complicated.

Search forum for WH_KEYBOARD_LL.

You'll have to get scan code from the structure passed as lParam in callback function.

Edit: see this #450718

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

If it involves scan codes, most likely you'll have to use keyboard hook. Luckily for you nowadays that isn't very complicated.

Search forum for WH_KEYBOARD_LL.

You'll have to get scan code from the structure passed as lParam in callback function.

Edit: see this #450718

That's what I was looking for... I remember someone had made this but couldn't find it.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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