InputMouseKeyboard

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
DevWithCoffee
Posts: 54
Joined: 13 Oct 2020, 12:16

InputMouseKeyboard

16 Sep 2023, 21:59

There probably already exists a function previously made for this purpose, but I couldn't find it.
I made this function so that LControl, RControl, LShift, RShift, mouse buttons 1 and 2 work together with the keyboard keys.

Function:

Code: Select all

InputMouseKeyboard(_fmt := 0, _md := "vk", _tmo := 0)
{
	; _fmt (Format):
	;   0 - Return KeyName
	;   1 - Return VK or SC (Hexadecimal)
	;   2 - Return Code (Decimal)
	;
	; _md (Mode):
	;   "vk" - VK (Virtual KeyCode)
	;   "sc" - SC (Scan Code)
	;
	; _tmo (TimeOut):
	;   0 - Ilimited
	;   1 or more - Count the seconds until you reach the same value

	if(_md <> "vk" && _md <> "sc")
	{
		_md := "vk"
	}
	sec := A_Sec, cou := 0, _cd := 1
	Loop
	{
		if(sec <> A_Sec && _tmo > 0)
		{
			Tooltip % "Count: " cou "`nSec: " sec "`nTimeout: " _tmo "`n_r: " _r
			cou++
			if(cou > _tmo)
			{
				 _r := 0
				 break
			}
			sec := A_Sec
		}
		; Ignore Common Shift, Control and Alt, working just with L or R
		if(_cd < 16 || _cd > 18)
		{
			_hx := Format(_md "{:x}", _cd)
		}
		if(GetKeyState(_hx) > 0)
		{
			_r := GetKeyName(_hx)
			if(StrLen(_r) == 1)
			{
				StringUpper, _r, _r
			}
			if(_fmt == 1)
			{
				_r := _hx
			}
			if(_fmt == 2)
			{
				_r := A_Index
			}
			break
		}
		_cd++
		if(_cd > 256)
		{
			_cd := 1
		}
	}
	return _r
}
Example of how to use it and what it is for:
_example.ahk
(1.83 KiB) Downloaded 28 times

Virtualkey list:
https://htmlpreview.github.io/?https://github.com/BossRpg/AHK_KeyListVKSC/blob/main/KeyListVK.html

Scancode:
https://htmlpreview.github.io/?https://github.com/BossRpg/AHK_KeyListVKSC/blob/main/KeyListSC.html

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 86 guests