|
|
|
01-26-2017, 02:47 PM
|
#1
|
Human being with feelings
Join Date: Feb 2014
Posts: 834
|
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()
|
|
|
01-26-2017, 03:20 PM
|
#2
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
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
|
|
|
01-26-2017, 03:35 PM
|
#3
|
Human being with feelings
Join Date: Feb 2014
Posts: 834
|
Thank you cfillion.
You rock!
|
|
|
01-26-2017, 04:32 PM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
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
|
|
|
01-26-2017, 06:58 PM
|
#5
|
Human being with feelings
Join Date: Feb 2014
Posts: 834
|
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 ?
|
|
|
01-26-2017, 08:45 PM
|
#6
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Not possible, sadly. I think it's possible to use Python scripts to make AutoHotKey send keypresses... not sure though.
|
|
|
01-27-2017, 01:39 AM
|
#7
|
Human being with feelings
Join Date: Feb 2014
Posts: 834
|
Ahh! Thanks again for the info.
|
|
|
06-10-2017, 06:41 PM
|
#8
|
Banned
Join Date: Nov 2015
Posts: 406
|
How come ctrl+i returns the same as tab?!?!
|
|
|
06-10-2017, 09:10 PM
|
#9
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
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.
|
|
|
05-08-2022, 04:30 AM
|
#10
|
Banned
Join Date: Dec 2018
Posts: 642
|
Numpad Key codes on Mac
On Mac, gfx.getchar() returns the same keycode (0x37) for both 'NumPad 7' and the regular keyboard '7' so how can we distinguish between these two different keys?
REAPER is able to distinguish them somehow. For example, in the Action List the numpad numbers show up as "NumPad n".
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 12:12 PM.
|