Uniquely identifying Logitech Unifying Keyboards (In C#) - c#

I have written a small program in C# 2010 which can split input from different keyboards by making an array of devices using, in part, the following:
--This code works fine for non-unified keyboards--
InputDevice id;
NumberOfKeyboards = id.EnumerateDevices();
id = new InputDevice( Handle );
id.KeyPressed += new InputDevice.DeviceEventHandler( m_KeyPressed );
private void m_KeyPressed( object sender, InputDevice.KeyControlEventArgs e ) {
lbDescription.Text = e.Keyboard.Name;
// e.Keyboard.* has many useful strings, none work for me anymore.
}
Very happy with this, I ran out and bought 4 Logitech K230 keyboards which use the Unifying receiver. Sadly, all the keyboard data is now multiplexed and shows up in my code as a single keyboard!
How can I identify which "unified" keyboard the input is coming from? Ideally in C#, but I suppose I am willing to look at other languages if solutions exist.

I don't have unifying keyboard, but check if you can see multiple keyboards in Windows devices. Then you could try this http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard and check output.

Related

Weighing Scale Barcode Reader C#

how can I convert an EAN-13 or Code-128 barcode generated from a weighing scale machine back to a user-defined object?
Class Product
{
string name = "Apples";
deciaml qty = "0.5";
double value = "5";
}
I already found libraries but all decodes barcode provided as an image. in my case, I have a barcode reader which will be reading the barcode label and input it as numbers something like (2032156478954).
what library or how can I decode those barcode numbers back to my object?
assume that I know from the user manual of the weighing scale which part is the product name, qty, and value
just like those label barcode we see in hypermarkets where you buy fruits and veggies in KG or Gram, it prints a barcode label, then the barcode label on POS is converted back to product object.
I am totally new when it comes to handling barcodes in .NET, any help, suggestion, or advice will be appreciated.
Example of Weighing Scale Barcode
Currently, I have solved it by implementing my own solution.
assume the barcode is 2 53647 2 5262 9 (EAN-13)
from the left-hand side, 2 tells the POS this is a barcode from the weighing scale machine, 53647 will be the ID of the item in the database.
2 tells the POS next 5 digits are the price of the item (52.62)
the last digit always discarded
the downside of this method is you will have to change either the settings of your weighing machine for every new setup you make to match your function. or you will change your code to match how the machine is printing barcodes since there is no one international standard.
I was hoping for a library that would have built-in functionality to recognize and decode those barcodes based on leading numbers and other check numbers. I might start building my own after looking at the most used formats.
If you already have a the string, as others pointed out you theoretically just nid to split the barcode and fill you class.
If you have a look here:
https://www.codeproject.com/Articles/10162/Creating-EAN-13-Barcodes-with-C
It shows you what the single numbers mean.
However:
If you want to figure out the values behind the numbers, then thats a little bit tricky. I expect the manufacturer code, if internationally standardized is something that will change over time. Because someone registers a new manufacturer and therefore gets a new code.
This would imply your programm needs access to the internet resp. to this database where they are registered.
Before putting to much effort in it, ask you self:
Do I really need to have this informations that well prepared, for the project am I'm doing or would it be completely fine if you just split the strings and have as manufacturer for example "50603" without knowing whats behind.
I just give you this sample for the EAN code, but I would say you can apply this to other codes as well.

Dial second part of an organization number when phone line is answered by TAPI in C#

I'm developing an application by TAPI technology in C#.
Suppose that I want to make a call to an organization that has a central device. I want when the target machine answers the phone line, my app dials the second number that is an internal number to that organization. I don't know how to dial the second number.
For example I want to call +1234567890 and when the phone line is answered, I want to dial 101 that is an internal number. My app dial's the first part of number perfectly, but i don't know how to code the second part.
numberList = "001234567890#101".Split('#');
tapiManager = new TapiManager(ProjectName);
tapiManager.Initialize();
lineName = (tapiManager != null && tapiManager.Lines.Length > 0 ? tapiManager.Lines[0].Name : string.Empty);
tapiline = tapiManager.GetLineByName(lineName, true);
if (tapiline == null)
tapiline = tapiManager.GetLineByName(lineName, true);
if (!tapiline.IsOpen)
tapiline.Open(MediaModes.DataModem);
makeCallParams = new MakeCallParams();
makeCallParams.DialPause = 2000;
tapiCall = tapiline.MakeCall(numberList[0], null, makeCallParams);
As you see the last line of my code dials the first number, but I can't find a way to dial the second part.
Any ideas about how I can do that?
This very much depends on what this central device is and how it handles your call, so I'll give a few examples:
An older (think analogue) PBX/Appliance will likely accept any digits after it has accepted the call. This you can do by including pauses in your number (usually "." or "," or "p") so "001234567890,,,,,101" (warning: not all TAPI drivers will support this). How many pauses really depends on the speed this central device picks up, too few it will cut of a part of the number, too much and it might hangup.
An IVR or PBX trunk that is specifically configured for this kind of setup should simply accept the full number in the original call, strip off the root number "001234567890" and dial "101" itself (strip out the "#").
An IVR/Voicemail or some other system that play's a message like "Which extension do you wish to call?" usually only accept digits after the message starts or end (barge-in allowed or not). Detecting voice is notoriously difficult, your best bet here is just to guess how long the message is, wait and then put the "101" on the line. (i don't know the lib you are using but the function is probably called GenerateDigits)

Burn cd audio with wmlib.dll without gabs in c# or vb.net

Good nights, I need the help the one who could. I burn a CD in format Audio with an object IWMPCdromBurn, nevertheless, between track and track stops two seconds of silence, which goes against what I need: I need that it reproduces without gaps, so that there is listened quite followed (Track At Once). If someone knows the solution it would do a good favor to myself... Later I leave my code
Private WithEvents player As New WindowsMediaPlayer()
Private Grabador As IWMPCdromBurn
Private listaGrabación As IWMPPlaylist = player.newPlaylist("plyList", "")
Grabador.burnPlaylist = listaGrabación
Grabador.burnFormat = WMPBurnFormat.wmpbfAudioCD
player.settings.autoStart = False
player.currentPlaylist = Grabador.burnPlaylist
Grabador.refreshStatus()
Grabador = CType(player.cdromCollection.getByDriveSpecifier(Me.cmbUnidades.SelectedItem), IWMPCdromBurn)
Grabador.startBurn()
To do that you need "disc-at-once" IWMPCdromBurn does not support that, sorry :-(
To do so-called "gapless audio", you must use a Disc-At-Once (DAO) recording method. The IDiscFormat2RawCD allows you to use different variations of DAO recording, however it requires a properly formatted stream.
Currently, IMAPIv2 does not support creating streams for this kind of audio disc.
https://social.msdn.microsoft.com/Forums/en-US/50f0d35b-7e6c-4deb-9c33-cfb76107c625/how-to-burn-audio-cd-using-disc-at-once?forum=windowsopticalplatform

Capture any kind of keystrokes (aka keylogger), preferably c# .net but any kind will do [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I need to capture everything that I type on my keyboard and then store it in numerous ways. I'd prefer it to be written in C# for .Net, but anything will do really.
My reasons to write this "keylogger" are simple:
Recently I became an owner of a Peregrine gaming glove. It's a very cool thing that allows you to issue commands by making gestures with your fingers, and at the same time, its a very thin glove so you can type with that hand with little discomfort.
Also, I have found a nice program called AutoHotkey that can severely boost your productivity by making macros for like any action. You can bind any key to any other key or series of keys or commands.
The problem is, you cannot tell it just like that "this is what I'm doing most" and "this is what I'm rarely using." Really, can you tell what key do you use more, page down or down? Do you use alt+tab more frequently that escape or layout switch (ctrl-shift or alt-shift)? I cannot tell that. I cannot tell which actions should I automate or switch to the more easy interface, without statistical data.
So I want to write a program to run in the background and log everything I type. This program will then store first, second and third order histogram of my actions (like, it will store how many times I pressed any single key, like entering, how many times I pressed a succession of two keys, like alt and then tab, and how many times I pressed a succession of three keys, like ctrl, alt and then deleted or ctrl,shift and then escape)
Then, after some time spent working/playing/whatever, I'll have information on what kind of actions should I try to bind to that interface (the glove) or automate with AutoHotkey program, to improve the speed of interacting with a PC.
In other words, simple science experiment, just for fun and progress :)
Old question but...
In Windows you can use the APIs of the user32.dll.
For a very simple keylogger you can use the method GetAsyncKeyState() checking whether each character of the ASCII table is pressed.
The whole code for a very simple and stupid keylogger written in a Console Application would be:
[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(Int32 i);
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(100);
for (int i = 0; i < 255; i++)
{
int keyState = GetAsyncKeyState(i);
// replace -32767 with 32769 for windows 10.
if (keyState == 1 || keyState == -32767)
{
Console.WriteLine((char)i);
break;
}
}
}
KeystrokeAPI
For those who are looking for something more robust and cleaner I've created an API that makes it easy. You only need to do this:
api.CreateKeyboardHook((character) => { Console.Write(character); });
More details here: https://github.com/fabriciorissetto/KeystrokeAPI
You need a global keyboard handler.
If this is windows you will have to use the Windows API and use the following:
SetWndowsHookEx
UnhookWindowsHookEx
CallNextHookEx
You need to set up a global "hook" to listen for keyboard and mouse events.
I have a C# class that does this and raises .Net keyboard and mouse event args, but I am not going to post the code online as this type of activity can be used for nefarious means.
Why did we do this? We embedded powerpoint into our application, but we didn't want the user editing the powerpoint slides while viewing them so from our C# application we set up a hook to monitor and intercept mouse and keyboard events if they were in the powerpoint control. Worked great but we had to make sure:
They were in control in our application, our application was active, etc. Once you set up the hook, it listens/captures for everything including other applications, since we were canceling specific keyboard actions we only wanted it when we needed it.
Here's an API link.
http://msdn.microsoft.com/en-us/library/ff468842(v=VS.85).aspx

Keyboard Type (Qwerty or Dvorak) detection

I was asked this question by a friend, and it piqued my curiosity, and I've been unable to find a solution to it yet, so I'm hoping someone will know.
Is there any way to programatically detect what type of keyboard a user is using? My understanding of the keyboard is that the signal sent to the computer for 'A' on a DVORAK keyboard is the same as the signal sent to the computer for an 'A' in a QUERTY keyboard. However, I've read about ways to switch to/from dvorak, that highlight registry tweaking, but I'm hoping there is a machine setting or some other thing that I can query.
Any ideas?
You can do this by calling the GetKeyboardLayoutName() Win32 API method.
Dvorak keyboards have specific names. For example, the U.S. Dvorak layout has a name of 00010409.
Code snippet:
public class Program
{
const int KL_NAMELENGTH = 9;
[DllImport("user32.dll")]
private static extern long GetKeyboardLayoutName(
System.Text.StringBuilder pwszKLID);
static void Main(string[] args)
{
StringBuilder name = new StringBuilder(KL_NAMELENGTH);
GetKeyboardLayoutName(name);
Console.WriteLine(name);
}
}
that probably depends on the OS. I'm sure that there is an operatingsystem setting somewhere that registers the nationality of the keyboard. (Dvorak is considered a nationality because French keyboards are different from US keyboards are different from ...)
Also, just a side note: 'A' was a bad example, as 'A' happens to be the same key in dvorak and qwerty... B-)
You might be able to do it via DirectInput, or whatever the current DirectX-equivalent is. I type on a Dvorak keyboard, and about 50% of the games I buy detect my keyboard and reconfigure the default keymappings to support it (using ,aoe instead of wasd, for instance)
And yes, as Brian mentioned, 'A' is the same on both keyboards.
Why would it matter? Depending on some special implementation of a keyboard is no good idea at all. We use barcode scanners all over the place that emulate keyboard inputs. What would your program do with these devices? :)
PS: the mentioned registry entry arranges the keys of a regular keyboard into dvorak layout.

Categories