Sign in to follow this  
Followers 0
Sori

How do I reroute a keypress?

6 posts in this topic

#1 ·  Posted (edited)

I have tried 2 solutions, with 2 different issues.

 

---------------------------------------------------------

Attempt 1:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>

Dim $reRouteKeys = 1

Global $hHook, $hStub_KeyProc, $buffer = ""
Local $hmod

$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

While 1
   If $reRouteKeys = 1 Then
      ToolTip("ReRoute: On", 5, 5)
   Else
      ToolTip("ReRoute: Off", 5, 5)
   EndIf
WEnd

Func EvaluateKey($keycode)
   If $keycode = 65 Then
      If $ReRouteKeys = 1 Then
         send("{1}")
      EndIf
   EndIf
EndFunc

;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    Else
        Local $flags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $flags
            Case $LLKHF_ALTDOWN
                ConsoleWrite("$LLKHF_ALTDOWN" & @CRLF)
            Case $LLKHF_EXTENDED
                ConsoleWrite("$LLKHF_EXTENDED" & @CRLF)
            Case $LLKHF_INJECTED
                ConsoleWrite("$LLKHF_INJECTED" & @CRLF)
            Case $LLKHF_UP
                ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @CRLF)
        EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
 EndFunc
 

 

The problem: When I press "a" it sends "1a"

How do I prevent the passthrough?

---------------------------------------------------------

 

Attempt 2:

#Include <HotKey.au3>
#Include <vkConstants.au3>

Dim $reRouteKeys = 1

_HotKey_Assign($VK_A, 'Message')

; Assign "CTRL-ESC" with Quit()
_HotKey_Assign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
   If $reRouteKeys = 1 Then
      ToolTip("ReRoute: On", 5, 5)
   Else
      ToolTip("ReRoute: Off", 5, 5)
   EndIf
WEnd

Func Message()
   If $reRouteKeys = 1 Then
      Send("{1}")
    Else 
      Send("{a}")
     EndIf
  EndFunc     ;==>Message

  Func   Quit()
      Exit
EndFunc     ;==>Quit
 

The problem: Send() does nothing.

If you place MsgBox(0, "Test", "Test") in the section, it will trigger the message box, so the function is being called, but send isn't working.

Edited by Melba23
Added code tags

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Sorimachi,

 

That took me a bit to color code it all

If you use code tags - see here how to do it you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

M23

Edit: And welcome to the AutoIt forum, by the way. :)

Edited by Melba23

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

Sorimachi,

welcome to AutoIt and the forum!

Can you please tell us why you need to reroute keypresses?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The idea popped in my head for a context sensitive keyboard.

I don't know what I would do with it though :D

I figured I would get the coding then throw it on the backburner for future useage.

And it's also challenging me and I don't like to be challenged.


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

I found this.

'?do=embed' frameborder='0' data-embedContent>>

It doesn't care about capitals or lowercase, is there a way to modify that?


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Using a mixture of ispressed and send() I got it all coded.

Thank you for trying to help.


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

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