Jump to content

Using HotKeySet() with imaginary key


corgano
 Share

Recommended Posts

Alright, so I found this tutorial the other day, that walks through remapping the capslock key to another key. I jumped on it, seeing how lapscock is probably the most useless key on the face fo the planet nowadays. I also realized i could map it to another key, such as numpaddot, and use it as a macro key

The problem is this: I want to use it as an AutoIt hotkey without making it another key on the keyboard: I want to assign it an "imaginary" key (like F13) and then be able to HotKeySet("{F13}"). Are there any keys not on a physical keyboard, that there exist AutoIt {keys} for? Or is there any way to use HotKeySet() with an "imaginary" key

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

The virtual key code can be found in the _IsPressed function.

And using Yashied's _WinAPI_MapVirtualKey function you can find the scan key code.

The example shows with F13 as a hot key Send("{F13}") will trigger that hot key.

Looking at _IsPressed Remarks, you will find the virtual key codes for F13 to F24.

;#Include "APIConstants.au3"
;#Include "WinAPIEx.au3"

HotKeySet("{F13}", "ImagineryKey")

; From _IsPressed Function "0x7C" is virtual key code for F13 key.
ConsoleWrite('Virtual-key code F13: 0x' & Hex(0x7C) & @CR)
ConsoleWrite('Scan code F13: 0x' & Hex(_WinAPI_MapVirtualKey(0x7C, 0)) & @CR); $MAPVK_VK_TO_VSC = 0
ConsoleWrite("----------------------------" & @LF)

; From _IsPressed Function "0x14" is virtual key code for CAPS LOCK key.
ConsoleWrite('Virtual-key code CAPS LOCK key: 0x' & Hex(0x14) & @CR)
ConsoleWrite('Scan code CAPS LOCK key: 0x' & Hex(_WinAPI_MapVirtualKey(0x14, 0)) & @CR) ; $MAPVK_VK_TO_VSC = 0

Send("{F13}")

Func ImagineryKey()
    ConsoleWrite("{F13} key pressed" & @LF)
EndFunc   ;==>ImagineryKey

; Copied from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/page__st__280#entry930607
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_MapVirtualKey
; Description....: Translates a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code.
; Syntax.........: _WinAPI_MapVirtualKey ( $iCode, $iType )
; Parameters.....: $iCode  - The virtual key code or scan code for a key. How this value is interpreted depends on the $iType parameter.
;                 $iType  - The translation to be performed. This value depends on the value of the $iCode parameter and can be
;                           one of the following values.
;
;                           $MAPVK_VK_TO_CHAR
;                           $MAPVK_VK_TO_VSC
;                           $MAPVK_VSC_TO_VK
;                           $MAPVK_VSC_TO_VK_EX
;
; Return values..: Success - A scan code, a virtual-key code, or a character value, depending on the above parameters.
;                 Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: An application can use _WinAPI_MapVirtualKey() to translate scan codes to the virtual-key code constants
;                 $VK_SHIFT, $VK_CONTROL, and $VK_MENU, and vice versa. These translations do not distinguish between the left and
;                 right instances of the SHIFT, CTRL, or ALT keys.
;
;                 An application can get the scan code corresponding to the left or right instance of one of these keys by calling
;                 _WinAPI_MapVirtualKey() with uCode set to one of the following virtual-key code constants.
;
;                 $VK_LSHIFT
;                 $VK_RSHIFT
;                 $VK_LCONTROL
;                 $VK_RCONTROL
;                 $VK_LMENU
;                 $VK_RMENU
;
; Related........:
; Link...........: @@MsdnLink@@ MapVirtualKey
; Example........: Yes
; ===============================================================================================================================

Func _WinAPI_MapVirtualKey($iCode, $iType)

    Local $Ret = DllCall('user32.dll', 'uint', 'MapVirtualKeyW', 'uint', $iCode, 'uint', $iType)

    If (@error) Or (Not $Ret[0]) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_MapVirtualKey

#cs
Output at console:-
Virtual-key code F13: 0x0000007C
Scan code F13: 0x0000000000000064
----------------------------
Virtual-key code CAPS LOCK key: 0x00000014
Scan code CAPS LOCK key: 0x000000000000003A
{F13} key pressed
#ce
Link to comment
Share on other sites

I'd argue that CapsLock is a lot more usefull than the Scroll Lock button, I use CapsLock a lot myself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I have a couple of KVM switches that use that key too, but other than that, I haven't seen a compelling reason to keep including a key from the data terminal days on a modern keyboard. :D

/thread-derail

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Speaking of terminal days, the only guy who should be drawn and quartered ahead of the CR/LF guy, is the dude who gave the OK to use spaces in Windows file paths. I bet it's still the cause of over 80% of programs failing to run on Windows. "Windows cannot find the file C:Program. Check the spelling and try again!" How about trying again with no spaces allowed for Windows 9?

Link to comment
Share on other sites

Ok, so slight problem. According to the script, the scancode for F13 should be 64, so I tried this and restarted my computer

Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,64,00,3a,00,00,00,00,00

Capslock was changed successfully, but using hotkeyset("{f3}","function") does not appear to work. Does anyone know why this is? Is 64 really the scancode for F13? Is there any way to test what key that button is now sending?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

ok, so I've tried a few more things. Instead of assigning it to F13, which I can't figure out what's not working, I tried remapping it to both shift+F1 and the media email key with no luck. Most google results for scancode lists are contradictory on the key codes for the F13-24 keys. Anyone know more about scancodes?

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Got a program called KeyTweak that has some nice functions, one of those is the teach mode, and half teach mode, with these, the program waits for a key to be input, and shows the key code, then you press the next one you want it to become, so to speak.

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

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