Jump to content

how to use keys combination to send a key ?


Recommended Posts

Hi!

Started with AutoIt just some hours ago so please be gentle with me.

so my keyboard "e" button is broken, but i dont want to buy a new keyboard yet, so after some thinking and browsing i decided to use autoit to fix my problem just for some time until i buy a new keyboard and i also want to take this chance to learn about autoit.

my idea is to use keys combination to send the "e" button.

so i want the script to function like this :

if i hold "q" button, and then press "w" button, the output will be "e" button.

i've tried it myself using example from this forum, but i got "error:unable to parse line".

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    If _IsPressed ("qw") Then
       Send("{a}")
    EndIf
WEnd
DllClose($dll)


hopefuly someone can give me a direction for this, thank you!

Link to comment
Share on other sites

  • Moderators

@Gaffgarion Welcome to the forum. First off, please re-read the _IsPressed section in the help file. You will see that you need to enter the value for the key, not the key itself (e.g. '51' not 'q'). Now, regarding your issue, there are a couple of ways to go about this. There is a UDF out there that you can use to set multiple hotkeys, you can find that here:

Alternatively, I like this little function written by Melba. In essence it uses HotKeySet on both keys and points them to the same function, then checks to see if both are pressed before sending the 'e' key.

;All credit to Melba23

#include <Misc.au3>
    HotKeySet("q", "_Q1")
    HotKeySet("w", "_Q1")

While 1
    Sleep(10)
WEnd

Func _Q1()
    ; Unset HotKeys to prevent possible double hit
    HotKeySet("q")
    HotKeySet("w")

    ; Are both keys pressed?
    $iBegin = TimerInit()
        Do
            If _IsPressed("51") And _IsPressed("57") Then Send("e", 1)
        Until TimerDiff($iBegin) > 100

    ; Reset HotKeys
    HotKeySet("q", "_Q1")
    HotKeySet("w", "_Q1")
EndFunc

Keep in mind, as the Remarks section of _IsPressed explain, even a brief press of the key combo can result in multiple presses of your output key, so you may get 'eeeee'

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

You were close, it's just the way you call it

If _IsPressed("28") And _IsPressed("DC") Then

Most complete answer from JLogan.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • 5 months later...
On 12/15/2017 at 9:00 PM, JLogan3o13 said:

even a brief press of the key combo can result in multiple presses of your output key, so you may get 'eeeee'

yes, its hard to use that script, because i only press both keys in just a brief moment and the output is like 'eeeeee'

i want it if i hold down Q key and then press W key 1x, the output is E key 1x, not multiple E key

i also found this by melba23

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")

HotKeySet("{q}","_Start") ; Fire HotKey on Q key
HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(10)
WEnd



Func _Start ()

    ; Look for W key
    If _IsPressed("57", $hDLL) Then
        ; Only action if BOTH pressed
        Send("e")
    EndIf



EndFunc



Func _Exit()
    DllClose($hDLL)
    Exit
EndFunc

this works perfectly, but its the opposite of what i want, for this one, i have to hold down W key first, and then press Q key.

what i needed is, hold down Q key first and then W key.

thanks

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