Jump to content

Detecting actual keypresses v. Send("{Key}"?


Recommended Posts

I have a directional pad in a gui that sends keypresses (up/down/left/right) - this works just fine. I also want to be able to detect when the user presses the actual up/down/left/right keys; however, when I am using "_IsPressed" it will detect both the actual keypresses, and the gui (simulated) keypresses. Is there a way to only detect (for example) the left arrow keypresses from the actual keyboard and not from: Send("{LEFT}") that the gui uses?

Thanks for any advice.

Link to comment
Share on other sites

Unset hotkey, Send(), set hotkey back.

What then would the point of the hot key be?

@ryantollefson

I don't know how to distinguish between a send and an actual key. If no-one has a solution then maybe you could do something like

;start of script

$totalkeysent = 0

$totalkeyin = 0

.

.

.

;when you send a key

countsend($key)

;when you detect a key

if _IsPressed($isk) then $totalkeyin += 1

if $totalkeyin > $totalsent then $usertypekey = true

Func countsend($kk)

send($kk)

$totalkeysent += 1

endfunc

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.
Link to comment
Share on other sites

effectively, like poisonkiller have suggested, this script is able to count only the number of "a" key which have been pressed with the keyboard :

#Include <Misc.au3>
HotKeySet("a","update_number_a")
$number_a=0

While 1
    send("a");to verify that these ones are not counted
    Sleep(1000)
WEnd


func update_number_a()
    If _IsPressed(41) Then 
        HotKeySet("a")
        Send("a")
        $number_a+=1
        ConsoleWrite($number_a&@CRLF)
        HotKeySet("a","update_number_a")
    EndIf
EndFunc
Link to comment
Share on other sites

effectively, like poisonkiller have suggested, this script is able to count only the number of "a" key which have been pressed with the keyboard :

#Include <Misc.au3>
HotKeySet("a","update_number_a")
$number_a=0

While 1
    send("a");to verify that these ones are not counted
    Sleep(1000)
WEnd
func update_number_a()
    If _IsPressed(41) Then 
        HotKeySet("a")
        Send("a")
        $number_a+=1
        ConsoleWrite($number_a&@CRLF)
        HotKeySet("a","update_number_a")
    EndIf
EndFunc

I think I'm beginning to catch up with everyone else in this thread :)

I see what is being said, Misha meant use Hotkeyset and don't use _Ispressed, I read it as use HotkeySet to detect the keyboard and not detect the send. Now it all makes sense. I was trying to deal with the problem but still use _IsPressed.

@Poisonkiller, apologies for my misunderstanding.

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.
Link to comment
Share on other sites

I have a directional pad in a gui that sends keypresses (up/down/left/right) - this works just fine. I also want to be able to detect when the user presses the actual up/down/left/right keys; however, when I am using "_IsPressed" it will detect both the actual keypresses, and the gui (simulated) keypresses. Is there a way to only detect (for example) the left arrow keypresses from the actual keyboard and not from: Send("{LEFT}") that the gui uses?

Thanks for any advice.

There's something I am definitely missing somewhere.

Are you talking about 2 different gui's running at the same time?

If not then how did your script detect a send("{LEFT}") using _IsPressed?

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