Xamarin / iOS - How to disable tab keycode from hardware keyboard - xamarin

I have a circumstance where a bluetooth barcode scanner is acting as a hardware keyboard in an Xamarin Forms application. The barcodes are encoded as such to contain a bit of information that needs to be parsed into different fields.
Unfortunately, some of the data is a tab character. iOS receives this hardware event in my app and once the tab pumps through, the next input field is focused and the barcode data continues to dump into that (the barcode scanner reads the data through "sequentially", as if to simulate you were typing it in).
At any rate; I'm having a heck of a time intercepting the "tab" character in an Entry (UITextView) in Xamarin/iOS.
I've set up an extension on Entry and associated a custom renderer with it (MyRenderer : EntryRenderer). Searching suggests that using Control.ShouldChangeTextInRange should work for character remapping, but the tab event happens on a different level it appears.
How can I stop a hardware keyboard "Tab" character in iOS from focusing onto the next field?

You could use KeyCommands to filter the Tab action in your EntryRenderer like this:
public override UIKeyCommand[] KeyCommands
{
get
{
UIKeyCommand newForwardKeyCommand = UIKeyCommand.Create(new NSString("\t"), 0, new ObjCRuntime.Selector("Excute"));
UIKeyCommand newBackKeyCommand = UIKeyCommand.Create(new NSString("\t"), UIKeyModifierFlags.Shift, new ObjCRuntime.Selector("Excute"));
UIKeyCommand[] keyCommands = { newForwardKeyCommand, newBackKeyCommand };
return keyCommands;
}
}
[Export("Excute")]
private void Excute()
{
Console.Write("Excute!");
}
Reference:https://stackoverflow.com/a/30876304/5474400

Related

Get keyboard type macOS and detect built-in, onscreen or USB

I am developing an application to detect keyboard type for macOS.
I have seen several functions which reading the documentation are supposed to return keyboard id.
However when I test those on my laptop it always print 59.
Can someone tell me where does this 59 value come from and its meaning ??
So far I have tried with oncreen keyboard and built-in keyboard. I have also tried with different layouts but I keep getting that 59
This is my code:
- (CGEventRef)processEvent:(CGEventRef)cgEvent
{
uint32_t kbdType = LMGetKbdType();
NSLog(#"Testing LMGetKbdType ----------> %d", kbdType);
NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];
NSEventType type = [event type];
if(type==NSKeyDown || type==NSKeyUp) {
int64_t val = CGEventGetIntegerValueField(cgEvent, kCGKeyboardEventKeyboardType);
NSLog(#"CGEventGetIntegerValueField: %lld",val);
EventRef ce = (EventRef)[event eventRef];
if(ce) {
unsigned kbt;
GetEventParameter(
ce,
kEventParamKeyboardType,
typeUInt32, NULL,
sizeof kbt, NULL,
& kbt
);
NSLog(#"CARBON Keyboard type: %d",kbt);
}
CGEventSourceRef evSrc = CGEventCreateSourceFromEvent( cgEvent );
if(evSrc) {
unsigned kbt = (NSUInteger) CGEventSourceGetKeyboardType( evSrc );
CFRelease(evSrc);
NSLog(#"COCOA: %d",kbt);
}
}
}
I think these are undocumented values with no external meaning. They are only useful for passing back into other APIs that need a keyboard type (e.g. UCKeyTranslate()).
I think that they are of the same kind that used to be documented in <CoreServices/CarbonCore/Gestalt.h>, under gestaltKeyboardType. However, that header is no longer being updated and doesn't list a type 59.
What exactly are you trying to figure out about the keyboard? If it's general layout, you can use KBGetLayoutType() to learn if it's ANSI, JIS, or ISO. You pass in the keyboard type, like the one you're getting from LMGetKbdType().
The active keyboard layout (e.g. U.S. vs. French vs. Dvorak) should not affect the keyboard type. The keyboard type is an aspect of the hardware and doesn't change as the layout (the interpretation of keys into characters) changes.

How to get the battery level from Kontakt.io beacons using AltBeacon API

I need to get the battery level from the kontakt.io beacons. I have set the layout as below and the DataFields are empty when I read the beacons in RangingBeaconsInRegion.
I was expecting I could read the battery level from the last bit as described in the Kontakt.io documentation.
This is my current code:
private BeaconManager InitializeBeaconManager()
{
BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
bm.BeaconParsers.Add(iBeaconParser);
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
return bm;
}
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
if (e.Beacons.Count > 0)
{
var beacon = e.Beacons.FirstOrDefault();
var data = beacon.DataFields.FirstOrDefault();
// here DataFields is empty!
}
}
I am using Xamarin Forms and this is the code for the Android Version.
Is this possible? or do I need to use the Kontakt.io API?
UPDATE
I have removed all parsers before apply the new layout and I am able to read the dataFields. However, I am getting a value 8 which I have no idea what this value means.
I am not positive the syntax on Xamarin, but try removing all existing beacon parsers before adding your custom one. I suspect the built in iBeacon parser is still active And it is matching first.
The battery level in Kontakt.io beacons are part of their "scan response packet", not part of the iBeacon structure, you'll have to use CoreBluetooth to read Characteristic 1, Service 5.
A quick breakdown of how this works is also described here, and the recently launched Xamarin component uses the same CoreBluetooth approach.

Showing full text in Pin's label in xamarin

I want to display text in multiple lines in the pin's label when it is clicked, but when I have a very long text to be displayed in Address it shows me only a part of it and rest of it remains hidden eg: 'Street 12A...'.
How can I make the label to display the whole text on clicking it and if possible then in multiple lines using Xamarin.Forms.Maps.
var pin = new Pin
{
Type = PinType.Place,
Position = position,
Label = "Label Name",
Address = "some text..........."
};
map.Pins.Add(pin);
You would be to create a custom render for map on each platform to replace the standard iOS pin annotations, Android pin markers, etc...
Xamarin has a full guide for creating custom pin annotations/markers and thus you can create the UI elements you need to display your full text.
Ref: https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/

How "print" (keyboard) button works?

I am very curious to know how "Print" button capture current screen? When we press "print" button what happens? How it'll capture the screen?
Please let me know if anyone know about the same.
Thanks, Jimit
ORIGINAL USE
Under command-line based operating systems such as MS-DOS, this key causes the contents of the current text mode screen memory buffer to be copied to the standard printer port, usually LPT1. In essence, whatever was currently on the screen when the key was pressed was printed. Pressing the Ctrl key in combination with Prt Sc turns on and off the "printer echo" feature. When echo is in effect, any conventional text output to the screen will be copied ("echoed") to the printer. There is also a Unicode character for print screen, U+2399 ⎙
.
MODERN USE
Newer-generation operating systems using a graphical interface tend to copy a bitmap image of the current screen to their clipboard or comparable storage area, which can be inserted into documents as a screenshot. Some shells allow modification of the exact behavior using modifier keys such as the control key.
Macintosh does not use a print screen key; instead, key combinations are used that start with ⌘ Cmd+⇧ Shift.
.
Coding
For example a C# code can run to take a screenshot:
private void PrtScr() {
Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bm as Image);
g.CopyFromScreen(0, 0, 0, 0, bm.Size);
bm.Save(#"C:\image.jpeg", ImageFormat.Jpeg);
}
For example Java code:
class ScreenRecorder {
public static void main(String args[]) {
try {
Toolkit tool = Toolkit.getDefaultToolkit();
Dimension d = tool.getScreenSize();
Rectangle rect = new Rectangle(d);
Robot robot = new Robot();
Thread.sleep(2000);
File f = new File("screenshot.jpg");
BufferedImage img = robot.createScreenCapture(rect);
ImageIO.write(img,"jpeg",f);
tool.beep();
} catch(Exception e){
e.printStackTrace();
}
}
}

WPF performance issue when trying to update listbox real-time based on user input

I'm new in Windows Phone development and i'm trying to develop a dictionary app.
I have a textbox to allow user input the word and a listbox to show all words which match the user input in real-time, so I'm used the textchanged event as below:
private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
wordNeedToDefine = searchTextBox.Text;
if (!(wordNeedToDefine == null || wordNeedToDefine.Equals("")))
{
var items = (from words in wordAndIndexList where words[0].StartsWith(wordNeedToDefine) select words[0]);
}
this.Dispatcher.BeginInvoke(() =>
{
wordsListBox.ItemsSource = items;
});
}
Everything is working fine but there are issues about performance, it's laggy when user input the text and listbox update the items.
Can someone tell me what i need to do to increase the performance. I'm also trying the AutoCompleteBox but it's have same problem.
Thanks in advance.
You'll get better performance if you use a CollectionViewSource to do the filtering and the more characters you have to filter will make it faster. i.e. Only start filtering once the user has entered at least 3 characters.

Resources