Old 01-26-2017, 02:47 PM   #1
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 610
Default Using multi-byte values - gfx.getchar(del)

Hi

I want to execute part of my code when Shift+Alt+Delete key pressed.
I don't know how to use multi-byte and Shift Alt Ctrl modifiers.
I'll appreciate if anyone could give me an example?

ReaScript API Doc:
Quote:
gfx.getchar([char])
If char is 0 or omitted, returns a character from the keyboard queue, or 0 if no character is available, or -1 if the graphics window is not open. If char is specified and nonzero, that character's status will be checked, and the function will return greater than 0 if it is pressed.

Common values are standard ASCII, such as 'a', 'A', '=' and '1', but for many keys multi-byte values are used, including 'home', 'up', 'down', 'left', 'rght', 'f1'.. 'f12', 'pgup', 'pgdn', 'ins', and 'del'.

Modified and special keys can also be returned, including:

Ctrl/Cmd+A..Ctrl+Z as 1..26
Ctrl/Cmd+Alt+A..Z as 257..282
Alt+A..Z as 'A'+256..'Z'+256
27 for ESC
13 for Enter
' ' for space
Code:
--keypress Example  
local name, x, y, w, h = "text demo", 200, 200, 200, 200

local del = 127 --It doesn't work
local char

local function Main()
	
	char = gfx.getchar(del)	
	if char == 27 or char == -1 then
		return 0
	else
		reaper.defer(Main)
	end

	gfx.x, gfx.y = 50, 50
	gfx.drawstr("char = "..char)	
	gfx.update()
	
end

gfx.init(name, x, y, 0, w, h)
Main()
__________________
Hope Sacred Passion Life Night Ache Soft Light
Outboarder is offline   Reply With Quote
Old 01-26-2017, 03:20 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 1,210
Default

You can read the state of modifier keys with gfx.mouse_cap (after calling gfx.getchar at least once).

Also, the key code for the Delete key in ReaScript GFX is 6579564, not 127 as in ASCII.



cfillion_GFX Keyboard Inspector.lua (not on ReaTeam Scripts as it's too much of a quick development tool)

Last edited by cfillion; 06-10-2017 at 06:52 PM. Reason: now on ReaTeam scripts as of 2017-06-10
cfillion is offline   Reply With Quote
Old 01-26-2017, 03:35 PM   #3
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 610
Default

Thank you cfillion.
You rock!
__________________
Hope Sacred Passion Life Night Ache Soft Light
Outboarder is offline   Reply With Quote
Old 01-26-2017, 04:32 PM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 4,213
Default

I can save you a bit of time here:
Code:
ESCAPE = 27,
SPACE = 32,
BACKSPACE = 8,
HOME = 1752132965,
END = 6647396,
INSERT = 6909555,
DELETE = 6579564,
RETURN = 13,
UP = 30064,
DOWN = 1685026670,
LEFT = 1818584692,
RIGHT = 1919379572,

F1 = 26161,
F2 = 26162,
F3 = 26163,
F4 = 26164,
F5 = 26165,
F6 = 26166,
F7 = 26167,
F8 = 26168,
F9 = 26169,
F10 = 6697264,
F11 = 6697265,
F12 = 6697266
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 01-26-2017, 06:58 PM   #5
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 610
Default

Thank you Lokasenna

Just before you post this I found it in your chord helper code.
Hope you fixed "chord_helper.lua:1799: attempt to compare two nil values" error
Can't wait to test it.

yet another question:

How to generate/send sequence of key combinations to reaper?
For example there is no action for Add fx chain (Shift+Insert,Shift+A).
Instead I want to pass Shift+Insert as key value/action.
Is it possible ?
__________________
Hope Sacred Passion Life Night Ache Soft Light
Outboarder is offline   Reply With Quote
Old 01-26-2017, 08:45 PM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 4,213
Default

Not possible, sadly. I think it's possible to use Python scripts to make AutoHotKey send keypresses... not sure though.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Old 01-27-2017, 01:39 AM   #7
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 610
Default

Ahh! Thanks again for the info.
__________________
Hope Sacred Passion Life Night Ache Soft Light
Outboarder is offline   Reply With Quote
Old 06-10-2017, 06:41 PM   #8
Airal
Human being with feelings
 
Join Date: Nov 2015
Posts: 376
Default

How come ctrl+i returns the same as tab?!?!
Airal is offline   Reply With Quote
Old 06-10-2017, 09:10 PM   #9
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 4,213
Default

Because keycodes are weird, is my guess.

When working with modifier keys you have to get the modifier separately via gfx.mouse_cap and then do a few comparisons to figure out what's being held down. It sucks.

Sexan and I worked out this much:
Code:
(I have no idea if the same values apply on a Mac)
					
Need to narrow the range to the normal keyboard ASCII values:
					
ASCII 'a' = 97
ASCII 'z' = 122
					
1-26		Ctrl+			char + 96
65-90		Shift/Caps+		char + 32
257-282		Ctrl+Alt+		char - 160
321-346		Alt+			char - 224

gfx.mouse_cap values:
					
4	Ctrl
8	Shift
16	Alt
32	Win
					
For Ctrl+4 or Ctrl+}... I have no fucking clue short of individually
checking every possibility.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.