in reply to Binding AltGr + minus key (=asterisk)

You can experiment with the following code. It might need some tweaking on MSWin or Mac:
#!/usr/bin/perl use warnings; use strict; use Tk qw{ MainLoop Ev }; my $mw = 'MainWindow'->new; $mw->Label(-text => 'Press any key')->pack; $mw->Entry(-textvariable => \ my $text, -state => 'readonly')->pack; $mw->bind('<KeyPress>', [sub { $text = $_[1] }, Ev('K')]); my @mods = ("", qw( Alt Shift Control Mod4 )); for my $p1 (0 .. $#mods) { for my $p2 (0 .. $#mods) { next if $p2 == 0 && $p1 != 0 || $p2 && $p1 >= $p2; for my $p3 (1 .. $#mods) { next if $p3 <= $p2; my $prefix = join '-', grep length, @mods[$p1, $p2, $p3]; $mw->bind("<$prefix-KeyPress>", [sub { $text = "$_[1] + $_ +[2]" }, "$prefix", Ev('K')]); } } } $mw->bind("<Alt-Shift-Control-Mod4-KeyPress>", [sub { $text = "$_[1] + $_[2]" }, 'Alt-Shift-Control-Meta', Ev('K')]); MainLoop();

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Binding AltGr + minus key (=asterisk)
by Anonymous Monk on May 01, 2024 at 23:00 UTC

    Dear Choroba,

    Thank you very much for the script. Unfortunately, it did not work on windows (I will try it on Linux tomorrow, although the target application must run on windows). The situation is: if I press AltGr, your script prints Control + ALT_R, but if I hold it down and press the minus key (which would create the asterisk), only minus appears in the entry. The situation is similar if I want to use 3 keys to create the asterisk: control + left alt + minus key. In this case also only the minus will remain in the entry at the end of the process.

    I also tried Term::Readkey to get the asterisk (not entered from numpad), but this is very difficult to implement in a Tk environment.